南鑫林 5 anni fa
parent
commit
3be8822897

+ 12 - 16
RainbowPlanet/RainbowPlanet/Manager/MapManager/BaiduMapManager/BaiduMapManager.swift

@@ -30,6 +30,8 @@ public class BaiduMapManager: NSObject {
     typealias LocationFalseBlock = () -> Void
 
     var  locationFalseBlock : LocationFalseBlock?
+    
+    var isLocation : Bool = false
 
     
     /// 初始化百度
@@ -81,6 +83,7 @@ public class BaiduMapManager: NSObject {
         
         locationManager.requestLocation(withReGeocode: true, withNetworkState: true) { [weak self] location, state, error in
             if (error != nil) {
+                 self?.isLocation = false
                 locationFalseBlock()
                 return
             } else {
@@ -110,6 +113,7 @@ public class BaiduMapManager: NSObject {
                     }
                     
                     LocationModel.shared().saveObject(locationModel: self?.locationModel ?? LocationModel())
+                    self?.isLocation = true
                     NXLLog(LocationModel.shared().object())
                     locationSuccessBlock()
                 }
@@ -120,28 +124,15 @@ public class BaiduMapManager: NSObject {
     
     /// 定位设置弹框
     func loacationAlertView() {
-        AlertSheetView.alert(title: "定位服务未开启", detailTitle: "请进入系统设置「设置」「隐私」「定位服务」中打开开关,并允许彩虹星球使用定位服务", cancelTitle: "取消", sureTitle: "立即开启", cancelBlock: { (popupView, Int, string) in
-            if let locationFalseBlock = self.locationFalseBlock {
-                locationFalseBlock()
-            }
-        }, confirmBlock: { (popupView, Int, string) in
+        AlertSheetView.alert(title: "定位服务未开启", detailTitle: "请进入系统设置「设置」「隐私」「定位服务」中打开开关,并允许由你使用定位服务", cancelTitle: "取消", sureTitle: "立即开启", cancelBlock: { (popupView, Int, string) in
 
+        }, confirmBlock: { (popupView, Int, string) in
             if #available(iOS 10.0, *) {
 
                 let url = URL(string: UIApplication.openSettingsURLString)
                 if let url = url {
                     if UIApplication.shared.canOpenURL(url) {
-                        UIApplication.shared.open(url, options: [:], completionHandler: { [weak self] success in
-                            self?.initLocation(locationSuccessBlock: {
-                                if let locationSuccessBlock = self?.locationSuccessBlock {
-                                    locationSuccessBlock()
-                                }
-                            }, locationFalseBlock: { [weak self] in
-                                if let locationFalseBlock = self?.locationFalseBlock {
-                                    locationFalseBlock()
-                                }
-                            })
-                        })
+                        UIApplication.shared.open(url, options: [:], completionHandler: { success in })
                     }
                 }
             } else {
@@ -152,7 +143,10 @@ public class BaiduMapManager: NSObject {
                     }
                 }
             }
+            popupView.hide()
+
         })
+        
     }
     
     
@@ -240,11 +234,13 @@ extension BaiduMapManager:BMKLocationManagerDelegate {
             //该值应用于iOS、tvos和watchos。它在上有售
             //macos,但kclauthorizationstatusauthorized是同义词且首选。
             startLocation()
+            self.isLocation = true
         }else if status == .authorizedWhenInUse {
             //只有在应用程序
             //对它们可见(如果继续在后台接收位置更新)。授权使用
             //尚未授予启动API。此值在MacOS上不可用。它应该在iOS、tvos和沃特克斯。
             startLocation()
+             self.isLocation = true
         }
         
     }

+ 9 - 11
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Follow/CommunityFollowViewController.swift

@@ -23,9 +23,7 @@ class CommunityFollowViewController: BaseViewController {
         }
     }
     weak var observe : NSObjectProtocol?
-    
-    var lastContentOffset : CGFloat = 0
-    
+        
     var navigationBarIsHidden: Bool = false
     
     var communityFollowDataModels : Array<CommunityFollowDataModel>?
@@ -298,7 +296,10 @@ extension CommunityFollowViewController {
     /// 删除帖子
     func communityDeleteApi(postId:Int,section:Int) {
         SwiftMoyaNetWorkServiceCommunity.shared().communityDeleteApi(postId: postId) { [weak self] (data) -> (Void) in
-            self?.communityFollowDataModels?.remove(at: section)
+            if !(self?.communityFollowDataModels?.isEmpty ?? true) {
+                self?.communityFollowDataModels?.remove(at: section)
+            }
+            
             self?.tableView.reloadData()
         }
     }
@@ -727,14 +728,11 @@ extension CommunityFollowViewController : UITableViewDelegate,UITableViewDataSou
 }
 
 extension CommunityFollowViewController {
-    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
-        //全局变量记录滑动前的contentOffset
-        lastContentOffset = scrollView.contentOffset.y;//判断上下滑动时
-    }
     
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
+        let point = scrollView.panGestureRecognizer.translation(in: self.view)
         
-        if scrollView.contentOffset.y > lastContentOffset {
+        if point.y < 0  {
             //向上
             if communityNavigationBarIsHidden == false && communityIndex != 2 {
                 NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: true)
@@ -745,10 +743,10 @@ extension CommunityFollowViewController {
                 self.view.layoutIfNeeded()
                 self.navigationBarIsHidden = true
             }
-        } else if scrollView.contentOffset.y < lastContentOffset && communityIndex != 2 {
+        } else  {
             //向下
             
-            if communityNavigationBarIsHidden {
+            if communityNavigationBarIsHidden && communityIndex != 2 {
                 NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: false)
                 tableView.snp.updateConstraints { (make) in
                     make.height.equalTo(kScreenHeight-48-kNavBarTotalHeight-kTabBarTotalHeight)

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Main/CommunityViewController.swift

@@ -227,10 +227,11 @@ class CommunityViewController: BaseViewController {
                 }
             }
             communityNavigationBarIsHidden = navigationBarIsHidden!
-            UIView.animate(withDuration: 0.5, animations: { [weak self] in
+            UIView.animate(withDuration: 0.15, animations: { [weak self] in
                 self?.view.layoutIfNeeded()
                 self?.listContainerView.layoutSubviews()
             }) { (complete) in}
+
         }
         
     }
@@ -414,7 +415,7 @@ extension CommunityViewController : JXSegmentedViewDelegate {
                      make.top.equalTo(kNavBarTotalHeight)
                 }
                 communityNavigationBarIsHidden = false
-                UIView.animate(withDuration: 0.5, animations: { [weak self] in
+                UIView.animate(withDuration: 0.15, animations: { [weak self] in
                     self?.view.layoutIfNeeded()
                     self?.listContainerView.layoutSubviews()
                 }) { (complete) in}

+ 12 - 13
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Recommend/CommunityRecommnendViewController.swift

@@ -24,8 +24,6 @@ class CommunityRecommnendViewController: UIViewController {
     /// 评论需要的模型
     var communityRecommendDataModel : CommunityRecommendDataModel?
     
-    var lastContentOffset : CGFloat = 0
-    
     var navigationBarIsHidden: Bool = false
     
     override func viewDidLoad() {
@@ -234,7 +232,9 @@ extension CommunityRecommnendViewController {
     /// 删除帖子
     func communityDeleteApi(postId:Int,section:Int) {
         SwiftMoyaNetWorkServiceCommunity.shared().communityDeleteApi(postId: postId) { [weak self] (data) -> (Void) in
-            self?.communityRecommendDataModels.remove(at: section)
+            if !(self?.communityRecommendDataModels.isEmpty ?? true) {
+                self?.communityRecommendDataModels.remove(at: section)
+            }
             self?.tableView.reloadData()
         }
     }
@@ -635,35 +635,34 @@ extension CommunityRecommnendViewController : UITableViewDelegate,UITableViewDat
 }
 
 extension CommunityRecommnendViewController {
-    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
-        //全局变量记录滑动前的contentOffset
-        lastContentOffset = scrollView.contentOffset.y;//判断上下滑动时
-    }
     
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
-        if scrollView.contentOffset.y > lastContentOffset && communityIndex != 2 {
+        
+        let point = scrollView.panGestureRecognizer.translation(in: self.view)
+        
+        if point.y < 0  {
             //向上
-            if communityNavigationBarIsHidden == false {
+            if communityNavigationBarIsHidden == false && communityIndex != 2 {
                 NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: true)
                 tableView.snp.updateConstraints { (make) in
                     make.height.equalTo(kScreenHeight-48-kSafeStatusBarHeight-kTabBarTotalHeight)
                 }
-//                self.view.layoutIfNeeded()
                 communityNavigationBarIsHidden = true
 
             }
-        } else if scrollView.contentOffset.y < lastContentOffset && communityIndex != 2 {
+        } else  {
             //向下
             
-            if communityNavigationBarIsHidden {
+            if communityNavigationBarIsHidden && communityIndex != 2 {
                 NotificationCenter.default.post(name: NSNotification.Name("CommunityViewControllerScrollView"), object: false)
                 tableView.snp.updateConstraints { (make) in
                     make.height.equalTo(kScreenHeight-48-kNavBarTotalHeight-kTabBarTotalHeight)
                 }
-//                self.view.layoutIfNeeded()
                 communityNavigationBarIsHidden = false
             }
         }
+        self.view.layoutIfNeeded()
+
     }
 }
 

+ 17 - 13
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddAddress/View/PublishAddressPOIView.swift

@@ -183,20 +183,24 @@ extension PublishAddressPOIView:UITableViewDataSource,UITableViewDelegate {
             case 0:
                 break
             default:
-                if self.suggestionList != nil {
-                    let locationModel = LocationModel.shared().object()
-                    let suggestionList = self.suggestionList?[indexPath.row]
-                    let city = suggestionList?.city ?? ""
-                    let district = suggestionList?.district ?? ""
-                    let key = suggestionList?.key ?? ""
-                    let latitude = "\(suggestionList?.location.latitude ?? 0)"
-                    let longitude = "\(suggestionList?.location.longitude ?? 0)"
-                    let toString = locationModel!.province  + city + district  + key
-                    didSelectBlock(latitude,longitude,toString)
+                if BaiduMapManager.shared.isLocation {
+                    if self.suggestionList != nil {
+                        let locationModel = LocationModel.shared().object()
+                        let suggestionList = self.suggestionList?[indexPath.row]
+                        let city = suggestionList?.city ?? ""
+                        let district = suggestionList?.district ?? ""
+                        let key = suggestionList?.key ?? ""
+                        let latitude = "\(suggestionList?.location.latitude ?? 0)"
+                        let longitude = "\(suggestionList?.location.longitude ?? 0)"
+                        let toString = (locationModel?.province ?? "")  + city + district  + key
+                        didSelectBlock(latitude,longitude,toString)
+                    }else {
+                        let selPoiName = self.poiList?[indexPath.row].name
+                        let locationModel = LocationModel.shared().object()
+                        didSelectBlock(locationModel!.latitude, locationModel!.longitude, selPoiName ?? "")
+                    }
                 }else {
-                    let selPoiName = self.poiList?[indexPath.row].name
-                    let locationModel = LocationModel.shared().object()
-                    didSelectBlock(locationModel!.latitude, locationModel!.longitude, selPoiName ?? "")
+                    BaiduMapManager.shared.loacationAlertView()
                 }
                 break
             }

+ 9 - 3
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishAddAddress/ViewController/PublishAddAddressController.swift

@@ -8,6 +8,9 @@
 
 import UIKit
 
+
+
+
 class PublishAddAddressController: BaseViewController {
     
     override func didReceiveMemoryWarning() {
@@ -18,8 +21,10 @@ class PublishAddAddressController: BaseViewController {
         NXLLog("deinit")
     }
     
+    
     typealias SelectLocationClosure = (_ address:String) -> Void
     var selectLocationClosure : SelectLocationClosure?
+   
     
     var locationAddress: String?
     /// 纬度
@@ -33,15 +38,16 @@ class PublishAddAddressController: BaseViewController {
         super.viewDidLoad()
         setupViews()
         setupLayouts()
-        
-        BaiduMapManager.shared.startLocation()
         BaiduMapManager.shared.locationSuccessBlock =  {
             [weak self] in
             self?.poiList = LocationModel.shared().object()?.poiList ?? []
             self?.addressPOIView.poiList = self?.poiList
         }
-        BaiduMapManager.shared.locationFalseBlock =  {            SwiftProgressHUD.shared().showText("定位失败")
+        BaiduMapManager.shared.locationFalseBlock =  {
+            BaiduMapManager.shared.loacationAlertView()
         }
+        BaiduMapManager.shared.startLocation()
+
     }
     
     override func viewWillAppear(_ animated: Bool) {