54 ol-54"> 100 50
         }
101 51
         return nil
102 52
     }
103
-
104
-    func getNavigationBarBounds() -> CGRect {
105
-        let statusHeight = UIApplication.shared.statusBarFrame.height
106
-        return CGRect(x: 0, y: -statusHeight, width: bounds.width, height: bounds.height + statusHeight)
53
+    
54
+    internal func apply(for configure: NavigationBarConfiguration) {
55
+        isHidden = configure.isHidden
56
+        isTranslucent = configure.isTranslucent
57
+        
58
+        barStyle = configure.barStyle
59
+        shadowImage = configure.shadowImage
60
+        setBackgroundImage(configure.backgroundImage, for: .default)
107 61
     }
108
-
109
-    override func value(forUndefinedKey key: String) -> Any? {
110
-        return nil
62
+    
63
+    internal convenience init(configure: NavigationBarConfiguration) {
64
+        self.init()
65
+        apply(for: configure)
111 66
     }
112 67
 }
113 68
 
114
-/// NavigationBar transition
115
-extension NavigationBar {
116
-    func constructViewHierarchy() {
117
-        setupShadowView()
118
-        setupBackgroundImageView()
119
-
120
-        guard let barBackground = getBarBackground() else { return }
121
-
122
-        insertSubview(shadowImageView, aboveSubview: barBackground)
123
-        insertSubview(backgroundImageView, aboveSubview: barBackground)
124
-        insertSubview(fakeView, belowSubview: backgroundImageView)
125
-        layoutIfNeeded()
126
-    }
127
-
128
-    private func setupShadowView() {
129
-        if let image = originShadowImage, image.size == CGSize.zero {
130
-            shadowImageView.image = image
131
-        } else {
132
-            shadowImageView.backgroundColor = UIColor(red: 0, green: 0, blue: 0,
133
-                                                      alpha: 77.0 / 255)
134
-        }
135
-
136
-        shadowImageView.alpha = originShadowImage == nil ? 1 : 0
137
-        getShadowView()?.isHidden = true
138
-    }
139
-
140
-    private func setupBackgroundImageView() {
141
-        if isPush {
142
-            fakeView.alpha = 0
143
-            backgroundImageView.image = targetBgImage
144
-        } else {
145
-            setBackgroundImage()
146
-            fakeView.alpha = 1
147
-            backgroundImageView.image = currBgImage
148
-        }
149
-    }
150
-
151
-    /// interactivePopGestureRecognizer
152
-    func transitionAnimationWithPercent(_ percent: CGFloat) {
153
-        switch bounce {
154
-        case .forward, .none:
155
-            transitionShadowAnimationWithPercent(percent)
156
-            transitionBackgroundAnimationWithPercent(percent)
157
-        case .backward:
158
-            transitionShadowAnimationWithPercent(1 - percent)
159
-            transitionBackgroundAnimationWithPercent(1 - percent)
160
-        }
161
-    }
162
-
163
-    func transitionAnimation() {
164
-        transitionShadowAnimation()
165
-        transitionBackgroundAnimation()
166
-    }
167
-
168
-    private func transitionShadowAnimation() {
169
-        guard hasChangedShadow else { return }
170
-        shadowImageView.alpha = originShadowImage == nil ? 0 : 1
171
-//        if originShadowImage == nil {
172
-//            shadowImageView.alpha = isInteractive ? (1 - percent) * 1 : 0
173
-//        } else {
174
-//            shadowImageView.alpha = isInteractive ? percent * 1 : 1
175
-//        }
69
+public extension UIToolbar {
70
+    func getBarBackground() -> UIView? {
71
+        return value(forKeyPath: "_backgroundView") as? UIView
176 72
     }
177
-
178
-    private func transitionBackgroundAnimation() {
179
-        guard hasChangedBgImage else { return }
180
-        if isPush {
181
-            fakeView.alpha = 1
182
-            backgroundImageView.frame.origin.x = 0
183
-        } else {
184
-            fakeView.alpha = 0
185
-            backgroundImageView.frame.origin.x = bounds.width
73
+    
74
+    func getShadowView() -> UIView? {
75
+        guard let barBackground = getBarBackground() else { return nil }
76
+        for view in barBackground.subviews where view.bounds.height == 0.5 {
77
+            return view
186 78
         }
79
+        return nil
187 80
     }
188
-
189
-    private func transitionShadowAnimationWithPercent(_ percent: CGFloat) {
190
-        guard hasChangedShadow else { return }
191
-        shadowImageView.alpha = originShadowImage == nil ? (1 - percent) * 1 : percent * 1
192
-    }
193
-
194
-    private func transitionBackgroundAnimationWithPercent(_ percent: CGFloat) {
195
-        guard hasChangedBgImage else { return }
196
-        fakeView.alpha = (1 - percent) * 1
197
-        backgroundImageView.frame.origin.x = percent * bounds.width
198
-    }
199
-
200
-    func clear() {
201
-
202
-        if isPush && hasChangedBgImage { setBackgroundImage() }
203
-
204
-        if !isPush && bounce == .backward && hasChangedBgImage {
205
-            targetBgImage = currBgImage
206
-            setBackgroundImage()
207
-        }
208
-
209
-        getShadowView()?.isHidden = false
210
-
211
-        fakeView.removeFromSuperview()
212
-        shadowImageView.removeFromSuperview()
213
-        backgroundImageView.removeFromSuperview()
214
-
215
-        currBgImage = nil
216
-        targetBgImage = nil
217
-
218
-        hasChangedBgImage = false
219
-        hasChangedShadow = false
220
-
221
-        bounce = .none
81
+    
82
+    internal convenience init(configure: NavigationBarConfiguration) {
83
+        self.init()
84
+        isHidden = configure.isHidden
85
+        isTranslucent = configure.isTranslucent
86
+        
87
+        barStyle = configure.barStyle
88
+        setShadowImage(configure.shadowImage, forToolbarPosition: .any)
89
+        setBackgroundImage(configure.backgroundImage, forToolbarPosition: .any, barMetrics: .default)
222 90
     }
223 91
 }
224 92
 
225
-extension NavigationBar {
226
-    enum Bounce {
227
-        case none
228
-        case backward
229
-        case forward
93
+extension UIViewController {
94
+    internal func getFakeBarFrame(for navigationBar: UINavigationBar) -> CGRect? {
95
+        guard let backgroundView = navigationBar.getBarBackground(),
96
+            var frame = backgroundView.superview?.convert(backgroundView.frame, to: self.view)
97
+            else { return nil }
98
+        
99
+        frame.origin.x = self.view.bounds.origin.x
100
+        return frame
230 101
     }
231 102
 }

+ 50 - 0
PaiAi/PaiaiUIKit/Reusable/UIKit/NavigationController/NavigationBarConfiguration.swift

@@ -0,0 +1,50 @@
1
+//
2
+//  NavigationBarConfiguration.swift
3
+//  PaiaiUIKit
4
+//
5
+//  Created by ffib on 2019/5/8.
6
+//  Copyright © 2019 FFIB. All rights reserved.
7
+//
8
+
9
+import UIKit
10
+
11
+struct NavigationBarConfiguration {
12
+    var isHidden: Bool
13
+    var isTranslucent: Bool
14
+    
15
+    var barStyle: UIBarStyle
16
+    var shadowImage: UIImage?
17
+    var backgroundImage: UIImage?
18
+    
19
+    static var `default`: NavigationBarConfiguration {
20
+        return NavigationBarConfiguration()
21
+    }
22
+    
23
+    static var transparent: NavigationBarConfiguration {
24
+        return NavigationBarConfiguration(isHidden: false, isTranslucent: true,
25
+                                          shadowImage: UIImage(), backgroundImage: UIImage())
26
+    }
27
+    
28
+    init(isHidden: Bool = false,
29
+         isTranslucent: Bool = false,
30
+         tintColor: UIColor = .black,
31
+         shadowImage: UIImage? = nil,
32
+         barTintColor: UIColor? = nil,
33
+         backgroundImage: UIImage? = nil,
34
+         barStyle: UIBarStyle = .default,
35
+         titleTextAttributes: [NSAttributedString.Key: Any] = [:]) {
36
+        self.isHidden = isHidden
37
+        self.barStyle = barStyle
38
+        self.shadowImage = shadowImage
39
+        self.isTranslucent = isTranslucent
40
+        self.backgroundImage = backgroundImage
41
+    }
42
+    
43
+    init(navigationBar: UINavigationBar) {
44
+        isHidden = navigationBar.isHidden
45
+        barStyle = navigationBar.barStyle
46
+        shadowImage = navigationBar.shadowImage
47
+        isTranslucent = navigationBar.isTranslucent
48
+        backgroundImage = navigationBar.backgroundImage(for: .default)
49
+    }
50
+}

+ 90 - 55
PaiAi/PaiaiUIKit/Reusable/UIKit/NavigationController/NavigationController.swift

@@ -9,7 +9,13 @@
9 9
 import UIKit
10 10
 
11 11
 public class NavigationController: UINavigationController {
12
-
12
+    
13
+    private var operation: Operation = .none
14
+    private var barConfigures: [UIViewController?: NavigationBarConfiguration] = [:]
15
+    
16
+    private var _fromFakeBar = UIToolbar()
17
+    private var _toFakeBar = UIToolbar()
18
+    
13 19
     override public init(rootViewController: UIViewController) {
14 20
         super.init(navigationBarClass: NavigationBar.classForCoder(), toolbarClass: nil)
15 21
         self.viewControllers = [rootViewController]
@@ -28,41 +34,67 @@ public class NavigationController: UINavigationController {
28 34
         delegate = self
29 35
         interactivePopGestureRecognizer?.delegate = self
30 36
         interactivePopGestureRecognizer?.isEnabled = true
31
-
32
-        interactivePopGestureRecognizer?.addTarget(self,
33
-                                                   action: #selector(handlePop(gestureRecognizer:)))
34 37
     }
38
+    
39
+    public override func viewDidLayoutSubviews() {
40
+        super.viewDidLayoutSubviews()
41
+        if operation == .none { return }
42
+        navigationBar.getBarBackground()?.alpha = 0
43
+    }
44
+}
35 45
 
36
-    @objc
37
-    private func handlePop(gestureRecognizer: UIPanGestureRecognizer) {
38
-        guard let navBar = navigationBar as? NavigationBar else { return }
39
-        if gestureRecognizer.state == .began { navBar.isPush = false }
40
-
41
-        guard navBar.needsInteractive else { return }
42
-
43
-        let percent = gestureRecognizer.translation(in: view).x / view.bounds.width
44
-
45
-        if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
46
-            navBar.transitionAnimationWithPercent(percent)
46
+fileprivate extension NavigationController {
47
+    
48
+    func setFakeNavigationBar() {
49
+        UIView.setAnimationsEnabled(false)
50
+        guard let to = transitionCoordinator?.viewController(forKey: .to),
51
+            let from = transitionCoordinator?.viewController(forKey: .from) else { return }
52
+        
53
+        switch self.operation {
54
+        case .push:
55
+            barConfigures[to] = NavigationBarConfiguration(navigationBar: navigationBar)
56
+        case .pop:
57
+            navigationBar.setBackgroundImage(barConfigures[to]?.backgroundImage, for: .default)
58
+        default:
59
+            break
47 60
         }
61
+        
62
+        setToFakeNavigationBar(for: to)
63
+        setFromFakeNavigationBar(for: from)
64
+        
65
+        navigationBar.apply(for: .transparent)
66
+        UIView.setAnimationsEnabled(true)
67
+        
68
+        if barConfigures[to]?.isHidden != barConfigures[from]?.isHidden {
69
+            setNavigationBarHidden(barConfigures[to]?.isHidden ?? false, animated: true)
70
+        }
71
+    }
48 72
 
49
-        guard gestureRecognizer.state == .ended
50
-            || gestureRecognizer.state == .cancelled
51
-            || gestureRecognizer.state == .failed,
52
-            let coordinator = transitionCoordinator else { return }
53
-
54
-        navBar.bounce = percent < 0.5 ? .backward : .forward
55
-        let durationPercent = Double(percent < 0.5 ? coordinator.percentComplete : (1 - coordinator.percentComplete))
56
-        UIView.animate(withDuration: coordinator.transitionDuration * durationPercent,
57
-                       delay: 0,
58
-                       usingSpringWithDamping: 1,
59
-                       initialSpringVelocity: coordinator.completionVelocity,
60
-                       options: [],
61
-                       animations: {
62
-                        navBar.transitionAnimationWithPercent(1)
63
-        }, completion: { _ in
64
-            navBar.clear()
65
-        })
73
+    func setFromFakeNavigationBar(for from: UIViewController) {
74
+        if let navBarFrame = from.getFakeBarFrame(for: navigationBar) {
75
+            _fromFakeBar = UIToolbar(configure: barConfigures[from] ?? .default)
76
+            _fromFakeBar.delegate = self
77
+            _fromFakeBar.frame = navBarFrame
78
+            from.view.addSubview(_fromFakeBar)
79
+        }
80
+    }
81
+    
82
+    func setToFakeNavigationBar(for to: UIViewController) {
83
+        if let navBarFrame = to.getFakeBarFrame(for: navigationBar) {
84
+            _toFakeBar = UIToolbar(configure: barConfigures[to] ?? .default)
85
+            _toFakeBar.delegate = self
86
+            _toFakeBar.frame = navBarFrame
87
+            to.view.addSubview(_toFakeBar)
88
+        }
89
+    }
90
+    
91
+    func clearFake() {
92
+        _fromFakeBar.removeFromSuperview()
93
+        _toFakeBar.removeFromSuperview()
94
+        
95
+        guard let from = transitionCoordinator?.viewController(forKey: .from),
96
+            operation == .pop else { return }
97
+        barConfigures.removeValue(forKey: from)
66 98
     }
67 99
 }
68 100
 
@@ -72,37 +104,34 @@ extension NavigationController: UINavigationControllerDelegate {
72 104
                                      animationControllerFor operation: UINavigationController.Operation,
73 105
                                      from fromVC: UIViewController,
74 106
                                      to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
75
-        (navigationBar as? NavigationBar)?.isPush = operation == .push
107
+        self.operation = operation
76 108
         return nil
77 109
     }
78 110
 
79 111
     public func navigationController(_ navigationController: UINavigationController,
80 112
                                      willShow viewController: UIViewController,
81 113
                                      animated: Bool) {
82
-        guard let navBar = navigationBar as? NavigationBar,
83
-            navBar.needsInteractive else { return }
84
-
85
-        guard let coordinator = transitionCoordinator,
86
-            animated else {
87
-                navBar.setBackgroundImage()
88
-                navBar.clear()
89
-                return
114
+        if operation == .none {
115
+            self.barConfigures[viewController] = NavigationBarConfiguration(navigationBar: navigationBar)
116
+            return
90 117
         }
91
-
92
-        navBar.constructViewHierarchy()
93
-
94
-        guard !coordinator.isInteractive else { return }
95
-
96
-        coordinator.animate(alongsideTransition: { (transitionContext) in
97
-            DispatchQueue.main.async {
98
-                UIView.beginAnimations(nil, context: nil)
99
-                UIView.setAnimationCurve(transitionContext.completionCurve)
100
-                UIView.setAnimationDuration(transitionContext.transitionDuration)
101
-                navBar.transitionAnimation()
102
-                UIView.commitAnimations()
118
+        
119
+        transitionCoordinator?.animate(alongsideTransition: { context in
120
+            if context.isInteractive {
121
+                self.operation = .pop
122
+            }
123
+            self.setFakeNavigationBar()
124
+        }, completion: { context in
125
+            let vc: UIViewController?
126
+            if context.isCancelled {
127
+                self.operation = .push
128
+                vc = context.viewController(forKey: .from)
129
+            } else {
130
+                vc = context.viewController(forKey: .to)
103 131
             }
104
-        }, completion: { (_) in
105
-            navBar.clear()
132
+            self.navigationBar.getBarBackground()?.alpha = 1
133
+            self.navigationBar.apply(for: self.barConfigures[vc] ?? .default)
134
+            self.clearFake()
106 135
         })
107 136
     }
108 137
 }
@@ -115,3 +144,9 @@ extension NavigationController: UIGestureRecognizerDelegate {
115 144
         return true
116 145
     }
117 146
 }
147
+
148
+extension NavigationController: UIToolbarDelegate {
149
+    public func position(for bar: UIBarPositioning) -> UIBarPosition {
150
+        return .top
151
+    }
152
+}

+ 3 - 1
PaiAi/PaiaiUIKit/Reusable/UIKit/PageViewController/PageViewController.swift

@@ -69,7 +69,9 @@ open class PageViewController: UIViewController {
69 69
         contentRect = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
70 70
 
71 71
         if #available(iOS 11, *) {
72
-            scrollView.contentInsetAdjustmentBehavior = .never
72
+            scrollView.contentInsetAdjustmentBehavior = .automatic
73
+        } else {
74
+            automaticallyAdjustsScrollViewInsets = false
73 75
         }
74 76
 
75 77
         constructViewHierarchy()

+ 5 - 4
PaiAi/PaiaiUIKit/Reusable/UIKit/QR/QRCodeScanView.swift

@@ -82,14 +82,15 @@ import CoreImage
82 82
     }
83 83
 
84 84
     @objc func start() {
85
-        let queue = DispatchQueue(label: "FFIB.startScan.com")
86
-        queue.async {
87
-            self.qrscanner?.startScan()
85
+//        let queue = DispatchQueue(label: "FFIB.startScan.com")
86
+//        queue.async {
87
+        
88 88
             DispatchQueue.main.async {
89
+                self.qrscanner?.startScan()
89 90
                 self.qrmaskView?.startAnimation()
90 91
                 self.indicatorView.stopAnimating()
91 92
             }
92
-        }
93
+//        }
93 94
     }
94 95
 
95 96
     public func openLight() {

+ 1 - 1
PaiAi/PaiaiUIKit/Reusable/UIKit/QR/QRCodeScanner.swift

@@ -83,7 +83,7 @@ class QRCodeScanner: NSObject {
83 83
     }
84 84
     func startScan() {
85 85
         setScanArea()
86
-        captureSession.startRunning()
86
+//        captureSession.startRunning()
87 87
     }
88 88
 
89 89
     func stopScan() {

+ 3 - 1
PaiAi/Paiai_iOS/App/AppCoordinator.swift

@@ -70,11 +70,13 @@ fileprivate extension AppCoordinator {
70 70
 
71 71
         let homeCoordinator = HomeCoordinator(homeVC,
72 72
                                               navigationController: navigationController,
73
+                                              containerViewController: containerViewController,
73 74
                                               userInfoViewModel: shareUserInfoViewModel)
74 75
         coordinate(to: homeCoordinator).subscribe().disposed(by: disposeBag)
75 76
 
76 77
         let messageCoordinator = MessageCoordinator(messageVC,
77
-                                                    navigationController: navigationController)
78
+                                                    navigationController: navigationController,
79
+                                                    containerViewController: containerViewController)
78 80
         coordinate(to: messageCoordinator).subscribe().disposed(by: disposeBag)
79 81
 
80 82
         containerViewController.pageItems = [PageItem(title: "首页",

+ 1 - 0
PaiAi/Paiai_iOS/App/ContainerViewController.swift

@@ -61,6 +61,7 @@ public final class ContainerViewController: PageViewController {
61 61
     }
62 62
 
63 63
     func setupNavigationBar() {
64
+        navigationController?.navigationBar.isTranslucent = true
64 65
         navigationController?.navigationBar.shadowImage = UIImage()
65 66
         navigationController?.navigationBar.tintColor = UIColor.white
66 67
         navigationController?.navigationBar.barTintColor = UIColor.white

+ 2 - 2
PaiAi/Paiai_iOS/App/Group/GroupViewController.swift

@@ -52,10 +52,10 @@ final class GroupViewController: UIViewController {
52 52
     override func viewDidLoad() {
53 53
         super.viewDidLoad()
54 54
         initalize()
55
+        navigationController?.navigationBar.setBackgroundImage(UIImage.Navigation.background, for: .default)
55 56
     }
56 57
 
57 58
     override func viewWillAppear(_ animated: Bool) {
58
-        navigationController?.navigationBar.setBackgroundImage(UIImage.Navigation.background, for: .default)
59 59
         super.viewWillAppear(animated)
60 60
     }
61 61
 
@@ -82,7 +82,7 @@ final class GroupViewController: UIViewController {
82 82
     }
83 83
 
84 84
     deinit {
85
-        collectionView.endAllRefreshing()
85
+        collectionView.removeAllPullToRefresh()
86 86
     }
87 87
 }
88 88
 

+ 3 - 1
PaiAi/Paiai_iOS/App/Home/HomeCoordinator.swift

@@ -13,14 +13,16 @@ import PaiaiDataKit
13 13
 class HomeCoordinator: BaseCoordinator<Void> {
14 14
 
15 15
     var homeViewController: HomeViewController
16
+    var containerViewController: ContainerViewController
16 17
     var shareUserInfoViewModel: UserInfoViewModel
17 18
 
18 19
     init(_ viewController: HomeViewController,
19 20
          navigationController: UINavigationController,
21
+         containerViewController: ContainerViewController,
20 22
          userInfoViewModel: UserInfoViewModel) {
21 23
         self.homeViewController = viewController
22 24
         self.shareUserInfoViewModel = userInfoViewModel
23
-
25
+        self.containerViewController = containerViewController
24 26
         super.init(navigationController: navigationController, viewController: viewController)
25 27
     }
26 28
 

+ 2 - 2
PaiAi/Paiai_iOS/App/Home/HomeViewController.swift

@@ -36,7 +36,7 @@ final class HomeViewController: UIViewController {
36 36
         collectionView.register(UINib(nibName: "PhotoCell",
37 37
                                       bundle: Bundle(identifier: "com.Paiai-iOS")),
38 38
                                 forCellWithReuseIdentifier: "photoCell")
39
-
39
+        
40 40
         setup()
41 41
         binding()
42 42
     }
@@ -62,7 +62,7 @@ final class HomeViewController: UIViewController {
62 62
     }
63 63
 
64 64
     deinit {
65
-        collectionView.endAllRefreshing()
65
+        collectionView.removeAllPullToRefresh()
66 66
     }
67 67
 }
68 68
 

+ 2 - 1
PaiAi/Paiai_iOS/App/Home/ScanQRViewController.swift

@@ -23,6 +23,7 @@ final class ScanQRViewController: UIViewController {
23 23
     override func viewDidLoad() {
24 24
         super.viewDidLoad()
25 25
         scanView.delegate = self
26
+        setNavigationBar()
26 27
         viewModel.join(code: "http://pai.ai/g/SpA5be3")
27 28
     }
28 29
 
@@ -32,8 +33,8 @@ final class ScanQRViewController: UIViewController {
32 33
     }
33 34
 
34 35
     override func viewWillAppear(_ animated: Bool) {
35
-        setNavigationBar()
36 36
         super.viewWillAppear(animated)
37
+        
37 38
     }
38 39
 
39 40
     override func viewWillDisappear(_ animated: Bool) {

+ 2 - 1
PaiAi/Paiai_iOS/App/Message/MessageCoordinator.swift

@@ -14,7 +14,8 @@ class MessageCoordinator: BaseCoordinator<Void> {
14 14
     fileprivate let messageViewController: MessageViewController
15 15
 
16 16
     init(_ viewController: MessageViewController,
17
-         navigationController: UINavigationController) {
17
+         navigationController: UINavigationController,
18
+         containerViewController: ContainerViewController) {
18 19
         messageViewController = viewController
19 20
         super.init(navigationController: navigationController, viewController: viewController)
20 21
     }

+ 1 - 1
PaiAi/Paiai_iOS/App/Message/MessageListViewController.swift

@@ -91,7 +91,7 @@ final class MessageListViewController: UIViewController {
91 91
     }
92 92
 
93 93
     deinit {
94
-        tableView.endAllRefreshing()
94
+        tableView.removeAllPullToRefresh()
95 95
     }
96 96
 }
97 97
 

+ 1 - 1
PaiAi/Paiai_iOS/App/Mine/MineGroupViewController.swift

@@ -58,7 +58,7 @@ final class MineGroupViewController: UIViewController {
58 58
     }
59 59
 
60 60
     deinit {
61
-        tableView.endAllRefreshing()
61
+        tableView.removeAllPullToRefresh()
62 62
     }
63 63
 }
64 64
 

+ 1 - 1
PaiAi/Paiai_iOS/App/Mine/MineOrderViewController.swift

@@ -55,7 +55,7 @@ final class MineOrderViewController: UIViewController {
55 55
     }
56 56
 
57 57
     deinit {
58
-        tableView.endAllRefreshing()
58
+        tableView.removeAllPullToRefresh()
59 59
     }
60 60
 }
61 61
 

fix navigation leftBarButton and rightBarButton offset bug below iOS 11 · 32804d6b53 - Gogs: Go Git Service

fix navigation leftBarButton and rightBarButton offset bug below iOS 11

FFIB 6 ans auparavant
Parent
Commettre
32804d6b53

+ 8 - 8
PaiAi/Paiai.xcodeproj/project.pbxproj

@@ -92,7 +92,6 @@
92 92
 		0513100021CA1B39004EF1BE /* CLLocationExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543272821C68C1900C6388D /* CLLocationExt.swift */; };
93 93
 		0513100121CA1B39004EF1BE /* CGPointExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543272921C68C1900C6388D /* CGPointExt.swift */; };
94 94
 		0513100221CA1B39004EF1BE /* CGSizeExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543272A21C68C1900C6388D /* CGSizeExt.swift */; };
95
-		0513100721CA1B39004EF1BE /* UIViewController+UIBarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6CCC0581E793DD0004BCC9D /* UIViewController+UIBarButtonItem.swift */; };
96 95
 		0513100A21CA1B39004EF1BE /* UIBarButtonItemExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543272E21C68C1900C6388D /* UIBarButtonItemExt.swift */; };
97 96
 		0513100B21CA1B39004EF1BE /* UIColorExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543272F21C68C1900C6388D /* UIColorExt.swift */; };
98 97
 		0513100F21CA1B39004EF1BE /* UIViewExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543273321C68C1900C6388D /* UIViewExt.swift */; };
@@ -198,6 +197,7 @@
198 197
 		0572B2C921E30D8000EAD2A2 /* PhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 054863671FA326CB00A39DA0 /* PhotoCell.xib */; };
199 198
 		057317A221F5C6A0009B2FCE /* BottomDefaultItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057317A121F5C6A0009B2FCE /* BottomDefaultItem.swift */; };
200 199
 		057317A421F5C6C0009B2FCE /* BottomCancelItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057317A321F5C6C0009B2FCE /* BottomCancelItem.swift */; };
200
+		057550BC22754ECB007A265D /* UINavigationItem+UIBarButttonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057550BB22754ECB007A265D /* UINavigationItem+UIBarButttonItem.swift */; };
201 201
 		057CA9BA21DC836B00FB7D03 /* GroupPhotoRemoteAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057CA9B921DC836B00FB7D03 /* GroupPhotoRemoteAPI.swift */; };
202 202
 		057CA9BC21DC855700FB7D03 /* UploadResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057CA9BB21DC855700FB7D03 /* UploadResource.swift */; };
203 203
 		057CA9C621DCA2C900FB7D03 /* PhotoRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057CA9C521DCA2C900FB7D03 /* PhotoRepository.swift */; };
@@ -208,7 +208,7 @@
208 208
 		0584FD7721F9C8A300FA1E3E /* PresentAnimatorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0584FD7621F9C8A300FA1E3E /* PresentAnimatorDelegate.swift */; };
209 209
 		0584FD7C21FABC1400FA1E3E /* PresentExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0584FD7B21FABC1400FA1E3E /* PresentExtension.swift */; };
210 210
 		0584FD7E21FABD9D00FA1E3E /* PresentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0584FD7D21FABD9D00FA1E3E /* PresentViewController.swift */; };
211
-		058C33EE2272F7BE00A435E9 /* UINavigationController + NavigationBack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 058C33ED2272F7BE00A435E9 /* UINavigationController + NavigationBack.swift */; };
211
+		058C33EE2272F7BE00A435E9 /* UINavigationController+NavigationBack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 058C33ED2272F7BE00A435E9 /* UINavigationController+NavigationBack.swift */; };
212 212
 		058D0C9D2249C94F006CA488 /* CoordinatorKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 058D0C9C2249C94F006CA488 /* CoordinatorKey.swift */; };
213 213
 		058D0CA02249FCF6006CA488 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 053E126A21F5696E00A64893 /* Toast.swift */; };
214 214
 		058D0CA12249FCF6006CA488 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0521145321F083F20047C55A /* ToastView.swift */; };
@@ -451,6 +451,7 @@
451 451
 		0572B2C021E2FB3E00EAD2A2 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = "<group>"; };
452 452
 		057317A121F5C6A0009B2FCE /* BottomDefaultItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomDefaultItem.swift; sourceTree = "<group>"; };
453 453
 		057317A321F5C6C0009B2FCE /* BottomCancelItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomCancelItem.swift; sourceTree = "<group>"; };
454
+		057550BB22754ECB007A265D /* UINavigationItem+UIBarButttonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationItem+UIBarButttonItem.swift"; sourceTree = "<group>"; };
454 455
 		0578947E20D264B300A9F773 /* MessageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewController.swift; sourceTree = "<group>"; };
455 456
 		057CA9B921DC836B00FB7D03 /* GroupPhotoRemoteAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupPhotoRemoteAPI.swift; sourceTree = "<group>"; };
456 457
 		057CA9BB21DC855700FB7D03 /* UploadResource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadResource.swift; sourceTree = "<group>"; };
@@ -462,7 +463,7 @@
462 463
 		0584FD7621F9C8A300FA1E3E /* PresentAnimatorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentAnimatorDelegate.swift; sourceTree = "<group>"; };
463 464
 		0584FD7B21FABC1400FA1E3E /* PresentExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentExtension.swift; sourceTree = "<group>"; };
464 465
 		0584FD7D21FABD9D00FA1E3E /* PresentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentViewController.swift; sourceTree = "<group>"; };
465
-		058C33ED2272F7BE00A435E9 /* UINavigationController + NavigationBack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController + NavigationBack.swift"; sourceTree = "<group>"; };
466
+		058C33ED2272F7BE00A435E9 /* UINavigationController+NavigationBack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+NavigationBack.swift"; sourceTree = "<group>"; };
466 467
 		058D0C9C2249C94F006CA488 /* CoordinatorKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoordinatorKey.swift; sourceTree = "<group>"; };
467 468
 		0594845721B528FE00074EFC /* Interfaces.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Interfaces.swift; sourceTree = "<group>"; };
468 469
 		059AA5D921BA1A2000485188 /* MessageCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCoordinator.swift; sourceTree = "<group>"; };
@@ -555,7 +556,6 @@
555 556
 		A69FFB8F1E7018CC0006FEE0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Main.storyboard; sourceTree = "<group>"; };
556 557
 		A69FFB911E7018CC0006FEE0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Message.storyboard; sourceTree = "<group>"; };
557 558
 		A69FFB931E7018CC0006FEE0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Mine.storyboard; sourceTree = "<group>"; };
558
-		A6CCC0581E793DD0004BCC9D /* UIViewController+UIBarButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+UIBarButtonItem.swift"; sourceTree = "<group>"; };
559 559
 /* End PBXFileReference section */
560 560
 
561 561
 /* Begin PBXFrameworksBuildPhase section */
@@ -940,8 +940,8 @@
940 940
 			children = (
941 941
 				0513105F21CA1E53004EF1BE /* UIStoryboardExt.swift */,
942 942
 				05C8D21A21ED9A020001E847 /* UIViewController+Navigation.swift */,
943
-				A6CCC0581E793DD0004BCC9D /* UIViewController+UIBarButtonItem.swift */,
944 943
 				0543272E21C68C1900C6388D /* UIBarButtonItemExt.swift */,
944
+				057550BB22754ECB007A265D /* UINavigationItem+UIBarButttonItem.swift */,
945 945
 				0543272F21C68C1900C6388D /* UIColorExt.swift */,
946 946
 				0543273321C68C1900C6388D /* UIViewExt.swift */,
947 947
 				0543273421C68C1900C6388D /* UIViewControllerExt.swift */,
@@ -1048,7 +1048,7 @@
1048 1048
 			isa = PBXGroup;
1049 1049
 			children = (
1050 1050
 				0500C26421E8644E009A7013 /* NavigationBackItemDelegate.swift */,
1051
-				058C33ED2272F7BE00A435E9 /* UINavigationController + NavigationBack.swift */,
1051
+				058C33ED2272F7BE00A435E9 /* UINavigationController+NavigationBack.swift */,
1052 1052
 			);
1053 1053
 			path = NavigationBack;
1054 1054
 			sourceTree = "<group>";
@@ -1614,12 +1614,11 @@
1614 1614
 				0584FD7521F9C70D00FA1E3E /* SideAnimator.swift in Sources */,
1615 1615
 				0584FD7721F9C8A300FA1E3E /* PresentAnimatorDelegate.swift in Sources */,
1616 1616
 				059B589F21F7103100FA64C2 /* AlertItem.swift in Sources */,
1617
-				058C33EE2272F7BE00A435E9 /* UINavigationController + NavigationBack.swift in Sources */,
1617
+				058C33EE2272F7BE00A435E9 /* UINavigationController+NavigationBack.swift in Sources */,
1618 1618
 				059B58A621F7235D00FA64C2 /* AlertAction.swift in Sources */,
1619 1619
 				0513109821CA3915004EF1BE /* QRCodeScanResult.swift in Sources */,
1620 1620
 				0513100221CA1B39004EF1BE /* CGSizeExt.swift in Sources */,
1621 1621
 				0513109A21CA3915004EF1BE /* QRCodeScanView.swift in Sources */,
1622
-				0513100721CA1B39004EF1BE /* UIViewController+UIBarButtonItem.swift in Sources */,
1623 1622
 				05D3A3C621FF010900A29A20 /* WebViewController.swift in Sources */,
1624 1623
 				0500C26521E8644E009A7013 /* NavigationBackItemDelegate.swift in Sources */,
1625 1624
 				057317A221F5C6A0009B2FCE /* BottomDefaultItem.swift in Sources */,
@@ -1668,6 +1667,7 @@
1668 1667
 				05C5285821FE995F0090ECB5 /* GestureRecognizerDelegate.swift in Sources */,
1669 1668
 				05130F6321C94C7A004EF1BE /* SideViewController.swift in Sources */,
1670 1669
 				05130F6421C94C7A004EF1BE /* PageViewController.swift in Sources */,
1670
+				057550BC22754ECB007A265D /* UINavigationItem+UIBarButttonItem.swift in Sources */,
1671 1671
 			);
1672 1672
 			runOnlyForDeploymentPostprocessing = 0;
1673 1673
 		};

BIN
PaiAi/Paiai.xcodeproj/project.xcworkspace/xcuserdata/FFIB.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 2
PaiAi/PaiaiUIKit/Reusable/Extension/UIKit/UIBarButtonItemExt.swift

@@ -32,7 +32,7 @@ public extension UIBarButtonItem {
32 32
     }
33 33
     
34 34
     convenience init(titles: [String], btnSpace: CGFloat, target: Any, actions: [Selector]) {
35
-        let barView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 44))
35
+        let barView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 36))
36 36
         var lastX: CGFloat = 0
37 37
         for (title, action) in zip(titles, actions) {
38 38
             let button = UIButton(type: .custom)
@@ -55,7 +55,7 @@ public extension UIBarButtonItem {
55 55
         
56 56
         for (target, (image, action)) in zip(targets, zip(images, actions)) {
57 57
             let button = UIButton(type: .custom)
58
-            button.frame = CGRect(x: lastX, y: 2, width: 36, height: 36)
58
+            button.frame = CGRect(x: lastX, y: 0, width: 36, height: 36)
59 59
             button.setImage(image, for: .normal)
60 60
             button.addTarget(target, action: action, for: .touchDown)
61 61
             barView.addSubview(button)

+ 29 - 0
PaiAi/PaiaiUIKit/Reusable/Extension/UIKit/UINavigationItem+UIBarButttonItem.swift

@@ -0,0 +1,29 @@
1
+//
2
+//  UINavigationItem+UIBarButttonItem.swift
3
+//  PaiaiUIKit
4
+//
5
+//  Created by ffib on 2019/4/28.
6
+//  Copyright © 2019 FFIB. All rights reserved.
7
+//
8
+
9
+import UIKit
10
+
11
+public extension UINavigationItem {
12
+    func setRightItem(_ item: UIBarButtonItem) {
13
+        if #available(iOS 11, *) {
14
+            rightBarButtonItem = item
15
+        } else {
16
+            let space = UIBarButtonItem(space: -15)
17
+            rightBarButtonItems = [space, item]
18
+        }
19
+    }
20
+    
21
+    func setLeftItem(_ item: UIBarButtonItem) {
22
+        if #available(iOS 11, *) {
23
+            leftBarButtonItem = item
24
+        } else {
25
+            let space = UIBarButtonItem(space: -15)
26
+            leftBarButtonItems = [space, item]
27
+        }
28
+    }
29
+}

+ 0 - 18
PaiAi/PaiaiUIKit/Reusable/Extension/UIKit/UIViewController+UIBarButtonItem.swift

@@ -1,18 +0,0 @@
1
-//
2
-//  UIViewController+UIBarButtonItem.swift
3
-//  PaiAi
4
-//
5
-//  Created by mac on 16/7/21.
6
-//  Copyright © 2016年 FFIB. All rights reserved.
7
-//
8
-
9
-import UIKit
10
-
11
-public extension UIViewController {
12
-    func setRightBarButtonItem(image: UIImage?, action: Selector) {
13
-        let button = UIButton(type: .custom)
14
-        button.setImage(image, for: .normal)
15
-        button.addTarget(self, action: action, for: .touchDown)
16
-        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
17
-    }
18
-}

+ 1 - 1
PaiAi/PaiaiUIKit/Reusable/UIKit/NavigationBack/UINavigationController + NavigationBack.swift

@@ -1,5 +1,5 @@
1 1
 //
2
-//  UINavigationController + NavigationBack.swift
2
+//  UINavigationController+NavigationBack.swift
3 3
 //  PaiaiUIKit
4 4
 //
5 5
 //  Created by ffib on 2019/4/26.

+ 1 - 5
PaiAi/Paiai_iOS/App/ContainerViewController.swift

@@ -72,11 +72,7 @@ public final class ContainerViewController: PageViewController {
72 72
     func constructNavigationViewHierarchy() {
73 73
         navigationContentView.addSubview(iconView)
74 74
         navigationContentView.addSubview(headerView)
75
-        let leftItem = UIBarButtonItem(customView: navigationContentView)
76
-        let spaceItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
77
-        spaceItem.width = -15
78
-        
79
-        navigationItem.leftBarButtonItems = [spaceItem, leftItem]
75
+        navigationItem.setLeftItem(UIBarButtonItem(customView: navigationContentView))
80 76
     }
81 77
 }
82 78
 

+ 1 - 1
PaiAi/Paiai_iOS/App/Group/GroupDetail/GroupDetailViewController.swift

@@ -34,7 +34,7 @@ final class GroupDetailViewController: UIViewController {
34 34
     
35 35
     func setRightBarButtonItems() {
36 36
         let item = UIBarButtonItem(image: UIImage(named: "navigation-right"), target: self, action: #selector(quit))
37
-        navigationItem.rightBarButtonItem = item
37
+        navigationItem.setRightItem(item)
38 38
     }
39 39
     
40 40
     @objc func quit() {

+ 1 - 2
PaiAi/Paiai_iOS/App/Group/GroupViewController.swift

@@ -171,8 +171,7 @@ extension GroupViewController {
171 171
                                    targets: [self, viewModel!],
172 172
                                    actions: [#selector(GroupViewController.presentGroupQR),
173 173
                                              #selector(GroupViewModel.navigateToGroupDetail)])
174
-
175
-        navigationItem.rightBarButtonItem = item
174
+        navigationItem.setRightItem(item)
176 175
     }
177 176
     
178 177
     @objc func presentGroupQR() {

+ 2 - 1
PaiAi/Paiai_iOS/App/Message/MessageListViewController.swift

@@ -53,7 +53,8 @@ final class MessageListViewController: UIViewController {
53 53
     
54 54
     private func setupNavigationBar() {
55 55
         navigationItem.title = type.model.title
56
-        setRightBarButtonItem(image: UIImage.Navigation.right, action: #selector(clearMessage))
56
+        let rightItem = UIBarButtonItem(image: UIImage.Navigation.right, target: self, action: #selector(clearMessage))
57
+        navigationItem.setRightItem(rightItem)
57 58
     }
58 59
 
59 60
     private func setup() {