├── .swift-versions ├── Example ├── Example │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── image1.imageset │ │ │ ├── 83312d5904eb35f2193368e6442b171d.jpg │ │ │ └── Contents.json │ │ ├── image2.imageset │ │ │ ├── 95573f72e3b68eb0527634dc3b3cd433.jpg │ │ │ └── Contents.json │ │ ├── image3.imageset │ │ │ ├── d76db5ab2b95629da799c61bf9e212b3.jpg │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── AppDelegate.swift │ └── ViewController.swift └── Example.xcodeproj │ └── project.pbxproj ├── ZYNavigationBar.xcworkspace ├── xcshareddata │ └── IDEWorkspaceChecks.plist └── contents.xcworkspacedata ├── ZYNavigationBar.podspec ├── ZYNavigationBar ├── ZYNavigationBar │ ├── ZYNavigationBar.h │ └── Info.plist └── ZYNavigationBar.xcodeproj │ └── project.pbxproj ├── LICENSE ├── README.md ├── Source ├── ZYNavigationBar.swift ├── UIViewController+Extension.swift └── ZYNavigationController.swift └── .gitignore /.swift-versions: -------------------------------------------------------------------------------- 1 | 5.0 2 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image1.imageset/83312d5904eb35f2193368e6442b171d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouyudk/ZYNavigationBar/HEAD/Example/Example/Assets.xcassets/image1.imageset/83312d5904eb35f2193368e6442b171d.jpg -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image2.imageset/95573f72e3b68eb0527634dc3b3cd433.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouyudk/ZYNavigationBar/HEAD/Example/Example/Assets.xcassets/image2.imageset/95573f72e3b68eb0527634dc3b3cd433.jpg -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image3.imageset/d76db5ab2b95629da799c61bf9e212b3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhouyudk/ZYNavigationBar/HEAD/Example/Example/Assets.xcassets/image3.imageset/d76db5ab2b95629da799c61bf9e212b3.jpg -------------------------------------------------------------------------------- /ZYNavigationBar.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ZYNavigationBar.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "83312d5904eb35f2193368e6442b171d.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "95573f72e3b68eb0527634dc3b3cd433.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/image3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "d76db5ab2b95629da799c61bf9e212b3.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ZYNavigationBar.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "ZYNavigationBar" 4 | s.version = "1.0.4" 5 | s.summary = "A Custom UINavigationBar." 6 | s.homepage = "https://github.com/zhouyudk/ZYNavigationBar/" 7 | s.license = { :type => "MIT", :file => "LICENSE" } 8 | s.author = { "yu zhou" => "384986004@qq.com" } 9 | s.source = { :git => "https://github.com/zhouyudk/ZYNavigationBar.git", :tag => s.version } 10 | s.source_files = "Source/*.swift" 11 | s.ios.deployment_target = "9.0" 12 | s.swift_versions = "5.0" 13 | end 14 | -------------------------------------------------------------------------------- /ZYNavigationBar/ZYNavigationBar/ZYNavigationBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYNavigationBar.h 3 | // ZYNavigationBar 4 | // 5 | // Created by yu zhou on 27/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ZYNavigationBar. 12 | FOUNDATION_EXPORT double ZYNavigationBarVersionNumber; 13 | 14 | //! Project version string for ZYNavigationBar. 15 | FOUNDATION_EXPORT const unsigned char ZYNavigationBarVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ZYNavigationBar/ZYNavigationBar/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 zhouyu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by yu zhou on 27/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ZYNavigationBar 4 | // 5 | // Created by yu zhou on 11/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZYNavigationBar 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var barAlphtLabel: UILabel! 15 | let vc = UIViewController() 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | self.automaticallyAdjustsScrollViewInsets = false 19 | vc.zy_barTintColor = UIColor.blue 20 | } 21 | 22 | override func viewDidAppear(_ animated: Bool) { 23 | super.viewDidAppear(animated) 24 | 25 | } 26 | 27 | override func didReceiveMemoryWarning() { 28 | super.didReceiveMemoryWarning() 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | @IBAction func barAlphaSliderHandle(_ sender: UISlider) { 33 | barAlphtLabel.text = "\(sender.value)" 34 | self.zy_barAlpha = CGFloat(sender.value) 35 | self.zy_needsUpdateNavigationBarAlpha() 36 | self.zy_needsUpdateNavigationBarShadowAlpha() 37 | } 38 | @IBAction func hiddenBarSwitchHandle(_ sender: UISwitch) { 39 | vc.zy_barIsHidden = sender.isOn 40 | } 41 | @IBAction func hiddenBarShadowSwitchHandle(_ sender: UISwitch) { 42 | vc.zy_barShadowIsHidden = sender.isOn 43 | } 44 | @IBAction func hiddenblackBarStyleSwitchHandle(_ sender: UISwitch) { 45 | vc.zy_barStyle = sender.isOn ? .black : .default 46 | } 47 | @IBAction func barBackgroundImageSwitchHandle(_ sender: UISwitch) { 48 | vc.zy_barImage = sender.isOn ? #imageLiteral(resourceName: "image1") : nil 49 | } 50 | @IBAction func barTintColorSegmentHandle(_ sender: UISegmentedControl) { 51 | switch sender.selectedSegmentIndex { 52 | case 0: 53 | vc.zy_barTintColor = UIColor.blue 54 | case 1: 55 | vc.zy_barTintColor = UIColor.red 56 | case 2: 57 | vc.zy_barTintColor = UIColor.yellow 58 | default: 59 | break 60 | } 61 | } 62 | 63 | @IBAction func pushtoNextVCButtonHandle(_ sender: UIButton) { 64 | let v = self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as! ViewController 65 | v.zy_barTintColor = vc.zy_barTintColor 66 | v.zy_barImage = vc.zy_barImage 67 | v.zy_barIsHidden = vc.zy_barIsHidden 68 | v.zy_barShadowIsHidden = vc.zy_barShadowIsHidden 69 | v.zy_barStyle = vc.zy_barStyle 70 | v.title = "\(Int(self.navigationItem.title!)!+1)" 71 | self.navigationController?.pushViewController(v, animated: true) 72 | } 73 | } 74 | 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZYNavigationBar 2 | 定制navigationBar,解决push/pop造成不同效果navigationBar突变,闪烁问题 3 | 4 | 5 | ## GIF展示 6 | ![image](https://note.youdao.com/yws/api/personal/file/WEB15de47d32d83166870a7e98f47ab8733?method=download&shareKey=fc081d7f877b9bb44649e3afb82affa0) 7 | ![image](https://note.youdao.com/yws/api/personal/file/WEB47d6d3ed1c80b01985e70825bc038ace?method=download&shareKey=dd10f88528dde7f4d28594912ce9df45) 8 | ![image](https://note.youdao.com/yws/api/personal/file/WEBcf69ae46f80304157c3f7d69cfefdda0?method=download&shareKey=adef0433b241a3e4c0bd2836687b284a) 9 | ![image](https://note.youdao.com/yws/api/personal/file/WEB112faeaef4c35097821b40097fa6784d?method=download&shareKey=9b879bd7f76386dfd1323ef9ed4161ce) 10 | 11 | 12 | ## 安装 13 | 14 | ### CocoaPods 15 | 16 | 1. 在 `Podfile` 中添加 `pod 'ZYNavigationBar'` 17 | 2. 执行 `pod install` 或 `pod update` 18 | 3. 导入 import ZYNavigationBar 19 | 20 | ### 手动安装 21 | 22 | 1. 下载 `ZYNavigationBar` 文件夹内的所有内容。 23 | 2. 将 `ZYNavigationBar` 内 `Source` 目录文件添加(拖放)到你的工程。 24 | 25 | ## 使用 26 | #### 1. 代码使用 `ZYNavigationController` 创建 27 | 28 | ```swift 29 | let vc = UIViewController() 30 | let navigationController = ZYNavigationController(rootViewController: vc) 31 | vc.zy_barTintColor = UIColor.blue 32 | ``` 33 | #### 2. 在storyboard中使用 34 | 35 | ![image](https://note.youdao.com/yws/api/personal/file/WEB602855175ebf8835cceaab95fb7d1528?method=download&shareKey=204ac1615682e569454bf933d446a9ef) 36 | 37 | ![image](https://note.youdao.com/yws/api/personal/file/WEBb6ec0e8fc4937f142ece67842d3846ff?method=download&shareKey=32f71f41c21f9d182b5d9e68572a9b4d) 38 | 39 | 40 | ### 使用 `UIViewController` 的扩展属性对navigationBar进行配置 41 | 42 | ```swift 43 | public var zy_barStyle: UIBarStyle //navigationBar样式 44 | 45 | public var zy_barTintColor: UIColor // navigationBar背景颜色 46 | 47 | public var zy_barImage: UIImage // navigationBar背景图片 48 | 49 | public var zy_tintColor: UIColor // navigationItem颜色 50 | 51 | public var zy_titleTextAttributes: [NSAttributedStringKey : Any] //navigationItem标题 52 | 53 | public var zy_barAlpha: CGFloat // navigationBar背景透明度 54 | 55 | public var zy_barIsHidden: Bool // 是否隐藏navigationBar 56 | 57 | public var zy_barShadowIsHidden: Bool // 是否隐藏navigationBar的shadow 58 | 59 | public var zy_backInteractive: Bool // 当前页面是否可以通过navigationBar返回按钮和右滑pop 60 | 61 | public var zy_swipeBackEnabled: Bool // 当前页面是否支持右滑 62 | ``` 63 | 64 | ## 注意事项 65 | 66 | 1. 当设置 `zy_barImage` 时,`zy_barTintColor` 将失效 67 | 2. 如果需要毛玻璃效果,可以设置 `zy_barTintColor` 时调整color的 `alpha` 值 68 | 3. 目前只支持 `isTranslucent` 为 `true` 69 | 4. `ZYNavigationBar` 必须配合 `ZYNavigationController` 一起使用,否则无效果 70 | 71 | ## Swift版本 72 | 73 | Swift 5.0 74 | 75 | 76 | ## Requirements 77 | 78 | iOS 9.0+ 79 | 80 | ## 参考 81 | 82 | [HBDNavigationBar](https://github.com/listenzz/HBDNavigationBar) 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Source/ZYNavigationBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZYNavigationBar.swift 3 | // ZYNavigationBar 4 | // 5 | // Created by yu zhou on 11/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class ZYNavigationBar: UINavigationBar { 12 | var shadowImageView: UIImageView = { 13 | let v = UIImageView() 14 | v.isUserInteractionEnabled = false 15 | v.contentScaleFactor = 1 16 | v.tag = 1 17 | return v 18 | }() 19 | var backgroundImageView: UIImageView = { 20 | let v = UIImageView() 21 | v.isUserInteractionEnabled = false 22 | v.contentScaleFactor = 1 23 | v.contentMode = .scaleToFill 24 | v.autoresizingMask = [.flexibleWidth, .flexibleHeight] 25 | v.contentMode = .scaleToFill 26 | v.tag = 1 27 | return v 28 | }() 29 | 30 | var fakeView: UIVisualEffectView = { 31 | let v = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffect.Style.light)) 32 | v.isUserInteractionEnabled = false 33 | v.autoresizingMask = [.flexibleHeight, .flexibleWidth] 34 | v.tag = 1 35 | return v 36 | }() 37 | 38 | public override var isTranslucent: Bool { 39 | get{ 40 | return super.isTranslucent 41 | }set{ 42 | if newValue == false { 43 | fatalError("isTranslucent must be true") 44 | } 45 | super.isTranslucent = true 46 | } 47 | } 48 | 49 | public override var barTintColor: UIColor? { 50 | get{ 51 | return self.fakeView.subviews.last?.backgroundColor 52 | }set{ 53 | self.fakeView.subviews.last?.backgroundColor = newValue//(newValue == nil ? UIColor.clear : newValue) 54 | } 55 | } 56 | 57 | /// 在swift中重写 shadowImage的get 和set会导致shadowImage始终显示,故此使用didset 58 | public override var shadowImage: UIImage? { 59 | willSet{ 60 | self.shadowImageView.image = newValue 61 | } 62 | didSet{ 63 | super.shadowImage = UIImage() 64 | } 65 | } 66 | 67 | public override func layoutSubviews() { 68 | super.layoutSubviews() 69 | ///layoutSubviews方法中才能得到self.subviews.first,在awakfromxib和init中都是nil 70 | setupFakeView() 71 | guard let superViewBounds = self.fakeView.superview?.bounds else { return } 72 | self.fakeView.frame = superViewBounds 73 | self.backgroundImageView.frame = superViewBounds 74 | self.shadowImageView.frame = CGRect(x: 0, y: superViewBounds.height-0.5, width: superViewBounds.width, height: 0.5) 75 | } 76 | 77 | /// 添加fakeView shadowView,bgView到navbar 78 | func setupFakeView() { 79 | guard let fsubView = self.subviews.first else { return } 80 | if self.fakeView.superview == nil{ 81 | fsubView.insertSubview(self.fakeView, at: 0) 82 | self.fakeView.bounds = (self.fakeView.superview?.bounds)! 83 | super.setBackgroundImage(UIImage(), for: .default) 84 | super.shadowImage = UIImage() 85 | } 86 | 87 | if self.backgroundImageView.superview == nil { 88 | fsubView.insertSubview(self.backgroundImageView, aboveSubview: self.fakeView) 89 | self.backgroundImageView.frame = (self.backgroundImageView.superview?.bounds)! 90 | } 91 | 92 | if self.shadowImageView.superview == nil { 93 | fsubView.insertSubview(self.shadowImageView, aboveSubview: self.backgroundImageView) 94 | self.shadowImageView.frame = CGRect(x: 0, y: (self.shadowImageView.superview?.bounds.height)!-0.5, width: (self.shadowImageView.superview?.bounds.width)!, height: 0.5) 95 | } 96 | } 97 | 98 | public override func setBackgroundImage(_ backgroundImage: UIImage?, for barMetrics: UIBarMetrics) { 99 | self.backgroundImageView.image = backgroundImage 100 | } 101 | 102 | } 103 | 104 | 105 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/swift,appcode,xcode,osx 3 | 4 | ### Swift ### 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | 9 | ## Build generated 10 | build/ 11 | DerivedData 12 | 13 | ## Various settings 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | 23 | *.xcuserstate 24 | project.xcworkspace 25 | xcuserdata 26 | UserInterfaceState.xcuserstate 27 | project.xcworkspace/ 28 | xcuserdata/ 29 | UserInterface.xcuserstate 30 | 31 | 32 | 33 | 34 | 35 | ## Other 36 | *.xccheckout 37 | *.moved-aside 38 | *.xcuserstate 39 | *.xcscmblueprint 40 | 41 | ## Obj-C/Swift specific 42 | *.hmap 43 | *.ipa 44 | 45 | # Swift Package Manager 46 | # 47 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 48 | # Packages/ 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | 59 | # Carthage 60 | # 61 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 62 | # Carthage/Checkouts 63 | 64 | Carthage/Build 65 | 66 | # fastlane 67 | # 68 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 69 | # screenshots whenever they are needed. 70 | # For more information about the recommended setup visit: 71 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 72 | 73 | fastlane/report.xml 74 | fastlane/screenshots 75 | 76 | 77 | ### AppCode ### 78 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 79 | 80 | *.iml 81 | 82 | ### Temporary files 83 | *.orig 84 | 85 | ## Directory-based project format: 86 | .idea/ 87 | # if you remove the above rule, at least ignore the following: 88 | 89 | # User-specific stuff: 90 | # .idea/workspace.xml 91 | # .idea/tasks.xml 92 | # .idea/dictionaries 93 | # .idea/shelf 94 | 95 | # Sensitive or high-churn files: 96 | # .idea/dataSources.ids 97 | # .idea/dataSources.xml 98 | # .idea/sqlDataSources.xml 99 | # .idea/dynamic.xml 100 | # .idea/uiDesigner.xml 101 | 102 | # Gradle: 103 | # .idea/gradle.xml 104 | # .idea/libraries 105 | 106 | # Mongo Explorer plugin: 107 | # .idea/mongoSettings.xml 108 | 109 | ## File-based project format: 110 | *.ipr 111 | *.iws 112 | 113 | ## Plugin-specific files: 114 | 115 | # IntelliJ 116 | /out/ 117 | 118 | # mpeltonen/sbt-idea plugin 119 | .idea_modules/ 120 | 121 | # JIRA plugin 122 | atlassian-ide-plugin.xml 123 | 124 | # Crashlytics plugin (for Android Studio and IntelliJ) 125 | com_crashlytics_export_strings.xml 126 | crashlytics.properties 127 | crashlytics-build.properties 128 | fabric.properties 129 | 130 | 131 | ### Xcode ### 132 | # Xcode 133 | # 134 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 135 | 136 | ## Build generated 137 | build/ 138 | DerivedData 139 | 140 | ## Various settings 141 | *.pbxuser 142 | !default.pbxuser 143 | *.mode1v3 144 | !default.mode1v3 145 | *.mode2v3 146 | !default.mode2v3 147 | *.perspectivev3 148 | !default.perspectivev3 149 | xcuserdata 150 | 151 | ## Other 152 | *.xccheckout 153 | *.moved-aside 154 | *.xcuserstate 155 | 156 | 157 | ### OSX ### 158 | .DS_Store 159 | .AppleDouble 160 | .LSOverride 161 | 162 | # Icon must end with two \r 163 | Icon 164 | 165 | 166 | # Thumbnails 167 | ._* 168 | 169 | # Files that might appear in the root of a volume 170 | .DocumentRevisions-V100 171 | .fseventsd 172 | .Spotlight-V100 173 | .TemporaryItems 174 | .Trashes 175 | .VolumeIcon.icns 176 | 177 | # Directories potentially created on remote AFP share 178 | .AppleDB 179 | .AppleDesktop 180 | Network Trash Folder 181 | Temporary Items 182 | .apdisk 183 | 184 | # rbenv 185 | .ruby-version 186 | 187 | 188 | -------------------------------------------------------------------------------- /Source/UIViewController+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+Extension.swift 3 | // ZYNavigationBar 4 | // 5 | // Created by yu zhou on 11/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public extension UIViewController { 12 | fileprivate struct ZYAssociatedKeys{ 13 | static var zy_barStyleKey = "zy_barStyleKey" 14 | static var zy_barTintColorKey = "zy_barTintColorKey" 15 | static var zy_barImageKey = "zy_barImageKey" 16 | static var zy_tintColorKey = "zy_tintColorKey" 17 | static var zy_titleTextAttributesKey = "zy_titleTextAttributesKey" 18 | static var zy_barAlphaKey = "zy_barAlphaKey" 19 | static var zy_barIsHiddenKey = "zy_barIsHiddenKey" 20 | static var zy_barShadowIsHiddenKey = "zy_barShadowIsHiddenKey" 21 | static var zy_backInteractiveKey = "zy_backInteractiveKey" 22 | static var zy_swipeBackEnabledKey = "zy_swipeBackEnabledKey" 23 | } 24 | 25 | /// navigationBar样式 26 | var zy_barStyle: UIBarStyle { 27 | get{ 28 | guard let style = objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barStyleKey) as? UIBarStyle else { 29 | return UINavigationBar.appearance().barStyle 30 | } 31 | return style 32 | }set{ 33 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barStyleKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 34 | } 35 | } 36 | 37 | /// navigationBar背景色,可以通过设置color的alpha值实现毛玻璃 38 | var zy_barTintColor: UIColor? { 39 | get { 40 | return objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barTintColorKey) as? UIColor 41 | }set { 42 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barTintColorKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 43 | self.zy_needsUpdateNavigationBarColorOrImage() 44 | } 45 | } 46 | 47 | /// navigationBar背景图,优先级高于zy_barTintColor,设置后zy_barTintColor失效 48 | var zy_barImage: UIImage? { 49 | get { 50 | return objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barImageKey) as? UIImage 51 | }set { 52 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barImageKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 53 | } 54 | } 55 | 56 | /// navigationItem颜色 57 | var zy_tintColor: UIColor { 58 | get{ 59 | guard let color = objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_tintColorKey) as? UIColor else { 60 | return UIColor.black//UINavigationBar.appearance().tintColor == nil ? : UINavigationBar.appearance().tintColor 61 | } 62 | return color 63 | }set { 64 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_tintColorKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 65 | } 66 | } 67 | 68 | /// navigationItem标题 69 | var zy_titleTextAttributes: [NSAttributedString.Key : Any] { 70 | get{ 71 | guard let attr = objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_titleTextAttributesKey) as? [NSAttributedString.Key : Any] else { 72 | return UINavigationBar.appearance().titleTextAttributes ?? [NSAttributedString.Key : Any]() 73 | } 74 | return attr 75 | }set { 76 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_titleTextAttributesKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 77 | } 78 | } 79 | 80 | /// navigationBar背景透明度 81 | var zy_barAlpha: CGFloat { 82 | get{ 83 | if self.zy_barIsHidden { 84 | return 0 85 | } 86 | guard let alpha = objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barAlphaKey) as? CGFloat else { 87 | return 1 88 | } 89 | return alpha 90 | }set { 91 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barAlphaKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 92 | } 93 | } 94 | 95 | /// 是否显示navigationBar 96 | var zy_barIsHidden: Bool { 97 | get{ 98 | return objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barIsHiddenKey) as? Bool ?? false 99 | }set { 100 | if newValue { 101 | self.navigationItem.leftBarButtonItem = UIBarButtonItem() 102 | self.navigationItem.titleView = UIView() 103 | self.navigationItem.hidesBackButton = true 104 | }else{ 105 | self.navigationItem.leftBarButtonItem = nil 106 | self.navigationItem.titleView = nil 107 | self.navigationItem.hidesBackButton = false 108 | } 109 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barIsHiddenKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 110 | } 111 | } 112 | 113 | /// 是否显示shadowImage 114 | var zy_barShadowIsHidden: Bool { 115 | get{ 116 | return zy_barIsHidden ? zy_barIsHidden : objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_barShadowIsHiddenKey) as? Bool ?? false 117 | }set { 118 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_barShadowIsHiddenKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 119 | } 120 | } 121 | /// 是否可以右滑返回和navigationBar返回按钮返回 122 | var zy_backInteractive: Bool { 123 | get{ 124 | return objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_backInteractiveKey) as? Bool ?? true 125 | }set { 126 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_backInteractiveKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 127 | } 128 | } 129 | 130 | /// 右滑返回 131 | var zy_swipeBackEnabled: Bool { 132 | get{ 133 | return objc_getAssociatedObject(self, &ZYAssociatedKeys.zy_swipeBackEnabledKey) as? Bool ?? true 134 | }set { 135 | objc_setAssociatedObject(self, &ZYAssociatedKeys.zy_swipeBackEnabledKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 136 | } 137 | } 138 | 139 | internal var zy_computedBarShadowAlpha: CGFloat { 140 | return self.zy_barShadowIsHidden ? 0 : self.zy_barAlpha 141 | } 142 | 143 | internal var zy_computedBarImage: UIImage? { 144 | let image = self.zy_barImage 145 | guard image == nil else { return image } 146 | guard self.zy_barTintColor == nil else { return nil } 147 | return UINavigationBar.appearance().backgroundImage(for: .default) 148 | } 149 | 150 | internal var zy_computedBarTintColor: UIColor? { 151 | guard self.zy_barImage == nil else { return nil } 152 | let color = self.zy_barTintColor 153 | guard color == nil else { return color } 154 | guard UINavigationBar.appearance().backgroundImage(for: .default) == nil else { return nil } 155 | guard UINavigationBar.appearance().barTintColor == nil else { return UINavigationBar.appearance().barTintColor } 156 | return UINavigationBar.appearance().barStyle == .default ? UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 0.8) : UIColor(red: 28/255, green: 28/255, blue: 28/255, alpha: 0.729) 157 | } 158 | 159 | 160 | func zy_needsUpdateNavigationBar() { 161 | guard let nav = self.navigationController as? ZYNavigationController else { return } 162 | nav.updateNavigationBarForViewController(controller: self) 163 | } 164 | 165 | func zy_needsUpdateNavigationBarAlpha() { 166 | guard let nav = self.navigationController as? ZYNavigationController else { return } 167 | nav.updateNavigationBarAlphaForViewController(self) 168 | } 169 | 170 | func zy_needsUpdateNavigationBarColorOrImage() { 171 | guard let nav = self.navigationController as? ZYNavigationController else { return } 172 | nav.updateNavigationBarColorOrImageForViewController(self) 173 | } 174 | 175 | func zy_needsUpdateNavigationBarShadowAlpha() { 176 | guard let nav = self.navigationController as? ZYNavigationController else { return } 177 | nav.updateNavigationBarShadowAlphaForViewController(self) 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /ZYNavigationBar/ZYNavigationBar.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B5C77DC7215CE5D9005A113D /* ZYNavigationBar.h in Headers */ = {isa = PBXBuildFile; fileRef = B5C77DC5215CE5D9005A113D /* ZYNavigationBar.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | B5C77DD1215CE5EA005A113D /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C77DCE215CE5EA005A113D /* UIViewController+Extension.swift */; }; 12 | B5C77DD2215CE5EA005A113D /* ZYNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C77DCF215CE5EA005A113D /* ZYNavigationBar.swift */; }; 13 | B5C77DD3215CE5EA005A113D /* ZYNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C77DD0215CE5EA005A113D /* ZYNavigationController.swift */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | B5C77DC2215CE5D9005A113D /* ZYNavigationBar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZYNavigationBar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | B5C77DC5215CE5D9005A113D /* ZYNavigationBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZYNavigationBar.h; sourceTree = ""; }; 19 | B5C77DC6215CE5D9005A113D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 20 | B5C77DCE215CE5EA005A113D /* UIViewController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = ""; }; 21 | B5C77DCF215CE5EA005A113D /* ZYNavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZYNavigationBar.swift; sourceTree = ""; }; 22 | B5C77DD0215CE5EA005A113D /* ZYNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZYNavigationController.swift; sourceTree = ""; }; 23 | /* End PBXFileReference section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | B5C77DBE215CE5D9005A113D /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXFrameworksBuildPhase section */ 34 | 35 | /* Begin PBXGroup section */ 36 | B5C77DB8215CE5D9005A113D = { 37 | isa = PBXGroup; 38 | children = ( 39 | B5C77DC4215CE5D9005A113D /* ZYNavigationBar */, 40 | B5C77DC3215CE5D9005A113D /* Products */, 41 | ); 42 | sourceTree = ""; 43 | }; 44 | B5C77DC3215CE5D9005A113D /* Products */ = { 45 | isa = PBXGroup; 46 | children = ( 47 | B5C77DC2215CE5D9005A113D /* ZYNavigationBar.framework */, 48 | ); 49 | name = Products; 50 | sourceTree = ""; 51 | }; 52 | B5C77DC4215CE5D9005A113D /* ZYNavigationBar */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | B5C77DCD215CE5EA005A113D /* Source */, 56 | B5C77DC5215CE5D9005A113D /* ZYNavigationBar.h */, 57 | B5C77DC6215CE5D9005A113D /* Info.plist */, 58 | ); 59 | path = ZYNavigationBar; 60 | sourceTree = ""; 61 | }; 62 | B5C77DCD215CE5EA005A113D /* Source */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | B5C77DCE215CE5EA005A113D /* UIViewController+Extension.swift */, 66 | B5C77DCF215CE5EA005A113D /* ZYNavigationBar.swift */, 67 | B5C77DD0215CE5EA005A113D /* ZYNavigationController.swift */, 68 | ); 69 | name = Source; 70 | path = ../../Source; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXHeadersBuildPhase section */ 76 | B5C77DBF215CE5D9005A113D /* Headers */ = { 77 | isa = PBXHeadersBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | B5C77DC7215CE5D9005A113D /* ZYNavigationBar.h in Headers */, 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXHeadersBuildPhase section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | B5C77DC1215CE5D9005A113D /* ZYNavigationBar */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = B5C77DCA215CE5D9005A113D /* Build configuration list for PBXNativeTarget "ZYNavigationBar" */; 90 | buildPhases = ( 91 | B5C77DBD215CE5D9005A113D /* Sources */, 92 | B5C77DBE215CE5D9005A113D /* Frameworks */, 93 | B5C77DBF215CE5D9005A113D /* Headers */, 94 | B5C77DC0215CE5D9005A113D /* Resources */, 95 | ); 96 | buildRules = ( 97 | ); 98 | dependencies = ( 99 | ); 100 | name = ZYNavigationBar; 101 | productName = ZYNavigationBar; 102 | productReference = B5C77DC2215CE5D9005A113D /* ZYNavigationBar.framework */; 103 | productType = "com.apple.product-type.framework"; 104 | }; 105 | /* End PBXNativeTarget section */ 106 | 107 | /* Begin PBXProject section */ 108 | B5C77DB9215CE5D9005A113D /* Project object */ = { 109 | isa = PBXProject; 110 | attributes = { 111 | LastUpgradeCheck = 1130; 112 | ORGANIZATIONNAME = "yu zhou"; 113 | TargetAttributes = { 114 | B5C77DC1215CE5D9005A113D = { 115 | CreatedOnToolsVersion = 9.1; 116 | LastSwiftMigration = 1120; 117 | ProvisioningStyle = Manual; 118 | }; 119 | }; 120 | }; 121 | buildConfigurationList = B5C77DBC215CE5D9005A113D /* Build configuration list for PBXProject "ZYNavigationBar" */; 122 | compatibilityVersion = "Xcode 8.0"; 123 | developmentRegion = en; 124 | hasScannedForEncodings = 0; 125 | knownRegions = ( 126 | en, 127 | Base, 128 | ); 129 | mainGroup = B5C77DB8215CE5D9005A113D; 130 | productRefGroup = B5C77DC3215CE5D9005A113D /* Products */; 131 | projectDirPath = ""; 132 | projectRoot = ""; 133 | targets = ( 134 | B5C77DC1215CE5D9005A113D /* ZYNavigationBar */, 135 | ); 136 | }; 137 | /* End PBXProject section */ 138 | 139 | /* Begin PBXResourcesBuildPhase section */ 140 | B5C77DC0215CE5D9005A113D /* Resources */ = { 141 | isa = PBXResourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | B5C77DBD215CE5D9005A113D /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | B5C77DD3215CE5EA005A113D /* ZYNavigationController.swift in Sources */, 155 | B5C77DD2215CE5EA005A113D /* ZYNavigationBar.swift in Sources */, 156 | B5C77DD1215CE5EA005A113D /* UIViewController+Extension.swift in Sources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXSourcesBuildPhase section */ 161 | 162 | /* Begin XCBuildConfiguration section */ 163 | B5C77DC8215CE5D9005A113D /* Debug */ = { 164 | isa = XCBuildConfiguration; 165 | buildSettings = { 166 | ALWAYS_SEARCH_USER_PATHS = NO; 167 | CLANG_ANALYZER_NONNULL = YES; 168 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 169 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 170 | CLANG_CXX_LIBRARY = "libc++"; 171 | CLANG_ENABLE_MODULES = YES; 172 | CLANG_ENABLE_OBJC_ARC = YES; 173 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 174 | CLANG_WARN_BOOL_CONVERSION = YES; 175 | CLANG_WARN_COMMA = YES; 176 | CLANG_WARN_CONSTANT_CONVERSION = YES; 177 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 180 | CLANG_WARN_EMPTY_BODY = YES; 181 | CLANG_WARN_ENUM_CONVERSION = YES; 182 | CLANG_WARN_INFINITE_RECURSION = YES; 183 | CLANG_WARN_INT_CONVERSION = YES; 184 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 185 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 186 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 187 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 188 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 189 | CLANG_WARN_STRICT_PROTOTYPES = YES; 190 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 191 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 192 | CLANG_WARN_UNREACHABLE_CODE = YES; 193 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 194 | CODE_SIGN_IDENTITY = "iPhone Developer"; 195 | COPY_PHASE_STRIP = NO; 196 | CURRENT_PROJECT_VERSION = 1; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu11; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 219 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 220 | VERSIONING_SYSTEM = "apple-generic"; 221 | VERSION_INFO_PREFIX = ""; 222 | }; 223 | name = Debug; 224 | }; 225 | B5C77DC9215CE5D9005A113D /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 232 | CLANG_CXX_LIBRARY = "libc++"; 233 | CLANG_ENABLE_MODULES = YES; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 236 | CLANG_WARN_BOOL_CONVERSION = YES; 237 | CLANG_WARN_COMMA = YES; 238 | CLANG_WARN_CONSTANT_CONVERSION = YES; 239 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 240 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 241 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 242 | CLANG_WARN_EMPTY_BODY = YES; 243 | CLANG_WARN_ENUM_CONVERSION = YES; 244 | CLANG_WARN_INFINITE_RECURSION = YES; 245 | CLANG_WARN_INT_CONVERSION = YES; 246 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 247 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 248 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 251 | CLANG_WARN_STRICT_PROTOTYPES = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | CODE_SIGN_IDENTITY = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | CURRENT_PROJECT_VERSION = 1; 259 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 260 | ENABLE_NS_ASSERTIONS = NO; 261 | ENABLE_STRICT_OBJC_MSGSEND = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu11; 263 | GCC_NO_COMMON_BLOCKS = YES; 264 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 265 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 266 | GCC_WARN_UNDECLARED_SELECTOR = YES; 267 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 268 | GCC_WARN_UNUSED_FUNCTION = YES; 269 | GCC_WARN_UNUSED_VARIABLE = YES; 270 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 271 | MTL_ENABLE_DEBUG_INFO = NO; 272 | SDKROOT = iphoneos; 273 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 274 | VALIDATE_PRODUCT = YES; 275 | VERSIONING_SYSTEM = "apple-generic"; 276 | VERSION_INFO_PREFIX = ""; 277 | }; 278 | name = Release; 279 | }; 280 | B5C77DCB215CE5D9005A113D /* Debug */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | CODE_SIGN_IDENTITY = ""; 284 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 285 | CODE_SIGN_STYLE = Manual; 286 | DEFINES_MODULE = YES; 287 | DEVELOPMENT_TEAM = ""; 288 | DYLIB_COMPATIBILITY_VERSION = 1; 289 | DYLIB_CURRENT_VERSION = 1; 290 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 291 | INFOPLIST_FILE = ZYNavigationBar/Info.plist; 292 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 293 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = zy.ZYNavigationBar; 296 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 297 | PROVISIONING_PROFILE_SPECIFIER = ""; 298 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 299 | SKIP_INSTALL = YES; 300 | SWIFT_VERSION = 5.0; 301 | TARGETED_DEVICE_FAMILY = "1,2"; 302 | }; 303 | name = Debug; 304 | }; 305 | B5C77DCC215CE5D9005A113D /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | CODE_SIGN_IDENTITY = ""; 309 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 310 | CODE_SIGN_STYLE = Manual; 311 | DEFINES_MODULE = YES; 312 | DEVELOPMENT_TEAM = ""; 313 | DYLIB_COMPATIBILITY_VERSION = 1; 314 | DYLIB_CURRENT_VERSION = 1; 315 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 316 | INFOPLIST_FILE = ZYNavigationBar/Info.plist; 317 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 318 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 319 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 320 | PRODUCT_BUNDLE_IDENTIFIER = zy.ZYNavigationBar; 321 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 322 | PROVISIONING_PROFILE_SPECIFIER = ""; 323 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 324 | SKIP_INSTALL = YES; 325 | SWIFT_VERSION = 5.0; 326 | TARGETED_DEVICE_FAMILY = "1,2"; 327 | }; 328 | name = Release; 329 | }; 330 | /* End XCBuildConfiguration section */ 331 | 332 | /* Begin XCConfigurationList section */ 333 | B5C77DBC215CE5D9005A113D /* Build configuration list for PBXProject "ZYNavigationBar" */ = { 334 | isa = XCConfigurationList; 335 | buildConfigurations = ( 336 | B5C77DC8215CE5D9005A113D /* Debug */, 337 | B5C77DC9215CE5D9005A113D /* Release */, 338 | ); 339 | defaultConfigurationIsVisible = 0; 340 | defaultConfigurationName = Release; 341 | }; 342 | B5C77DCA215CE5D9005A113D /* Build configuration list for PBXNativeTarget "ZYNavigationBar" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | B5C77DCB215CE5D9005A113D /* Debug */, 346 | B5C77DCC215CE5D9005A113D /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | /* End XCConfigurationList section */ 352 | }; 353 | rootObject = B5C77DB9215CE5D9005A113D /* Project object */; 354 | } 355 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B580DB0E242A02DE00E9B5C9 /* ZYNavigationBar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5C77DD6215CE626005A113D /* ZYNavigationBar.framework */; }; 11 | B580DB0F242A02DE00E9B5C9 /* ZYNavigationBar.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = B5C77DD6215CE626005A113D /* ZYNavigationBar.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 12 | B58BBB84215CE58000A9EB8D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58BBB83215CE58000A9EB8D /* AppDelegate.swift */; }; 13 | B58BBB86215CE58000A9EB8D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58BBB85215CE58000A9EB8D /* ViewController.swift */; }; 14 | B58BBB89215CE58000A9EB8D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B58BBB87215CE58000A9EB8D /* Main.storyboard */; }; 15 | B58BBB8B215CE58000A9EB8D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B58BBB8A215CE58000A9EB8D /* Assets.xcassets */; }; 16 | B58BBB8E215CE58000A9EB8D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B58BBB8C215CE58000A9EB8D /* LaunchScreen.storyboard */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXCopyFilesBuildPhase section */ 20 | B580DB10242A02DE00E9B5C9 /* Embed Frameworks */ = { 21 | isa = PBXCopyFilesBuildPhase; 22 | buildActionMask = 2147483647; 23 | dstPath = ""; 24 | dstSubfolderSpec = 10; 25 | files = ( 26 | B580DB0F242A02DE00E9B5C9 /* ZYNavigationBar.framework in Embed Frameworks */, 27 | ); 28 | name = "Embed Frameworks"; 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | B58BBB80215CE58000A9EB8D /* ZYNavigationBarExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZYNavigationBarExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | B58BBB83215CE58000A9EB8D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | B58BBB85215CE58000A9EB8D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 37 | B58BBB88215CE58000A9EB8D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | B58BBB8A215CE58000A9EB8D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | B58BBB8D215CE58000A9EB8D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | B58BBB8F215CE58000A9EB8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | B5C77DD6215CE626005A113D /* ZYNavigationBar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ZYNavigationBar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | B58BBB7D215CE58000A9EB8D /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | B580DB0E242A02DE00E9B5C9 /* ZYNavigationBar.framework in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | B58BBB77215CE58000A9EB8D = { 57 | isa = PBXGroup; 58 | children = ( 59 | B58BBB82215CE58000A9EB8D /* Example */, 60 | B58BBB81215CE58000A9EB8D /* Products */, 61 | B5C77DD4215CE626005A113D /* Frameworks */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | B58BBB81215CE58000A9EB8D /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | B58BBB80215CE58000A9EB8D /* ZYNavigationBarExample.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | B58BBB82215CE58000A9EB8D /* Example */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | B58BBB83215CE58000A9EB8D /* AppDelegate.swift */, 77 | B58BBB85215CE58000A9EB8D /* ViewController.swift */, 78 | B58BBB87215CE58000A9EB8D /* Main.storyboard */, 79 | B58BBB8A215CE58000A9EB8D /* Assets.xcassets */, 80 | B58BBB8C215CE58000A9EB8D /* LaunchScreen.storyboard */, 81 | B58BBB8F215CE58000A9EB8D /* Info.plist */, 82 | ); 83 | path = Example; 84 | sourceTree = ""; 85 | }; 86 | B5C77DD4215CE626005A113D /* Frameworks */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | B5C77DD6215CE626005A113D /* ZYNavigationBar.framework */, 90 | ); 91 | name = Frameworks; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | B58BBB7F215CE58000A9EB8D /* Example */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = B58BBB92215CE58000A9EB8D /* Build configuration list for PBXNativeTarget "Example" */; 100 | buildPhases = ( 101 | B58BBB7C215CE58000A9EB8D /* Sources */, 102 | B58BBB7D215CE58000A9EB8D /* Frameworks */, 103 | B58BBB7E215CE58000A9EB8D /* Resources */, 104 | B580DB10242A02DE00E9B5C9 /* Embed Frameworks */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = Example; 111 | productName = Example; 112 | productReference = B58BBB80215CE58000A9EB8D /* ZYNavigationBarExample.app */; 113 | productType = "com.apple.product-type.application"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | B58BBB78215CE58000A9EB8D /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastSwiftUpdateCheck = 0910; 122 | LastUpgradeCheck = 1120; 123 | ORGANIZATIONNAME = "yu zhou"; 124 | TargetAttributes = { 125 | B58BBB7F215CE58000A9EB8D = { 126 | CreatedOnToolsVersion = 9.1; 127 | LastSwiftMigration = 1120; 128 | ProvisioningStyle = Automatic; 129 | }; 130 | }; 131 | }; 132 | buildConfigurationList = B58BBB7B215CE58000A9EB8D /* Build configuration list for PBXProject "Example" */; 133 | compatibilityVersion = "Xcode 8.0"; 134 | developmentRegion = en; 135 | hasScannedForEncodings = 0; 136 | knownRegions = ( 137 | en, 138 | Base, 139 | ); 140 | mainGroup = B58BBB77215CE58000A9EB8D; 141 | productRefGroup = B58BBB81215CE58000A9EB8D /* Products */; 142 | projectDirPath = ""; 143 | projectRoot = ""; 144 | targets = ( 145 | B58BBB7F215CE58000A9EB8D /* Example */, 146 | ); 147 | }; 148 | /* End PBXProject section */ 149 | 150 | /* Begin PBXResourcesBuildPhase section */ 151 | B58BBB7E215CE58000A9EB8D /* Resources */ = { 152 | isa = PBXResourcesBuildPhase; 153 | buildActionMask = 2147483647; 154 | files = ( 155 | B58BBB8E215CE58000A9EB8D /* LaunchScreen.storyboard in Resources */, 156 | B58BBB8B215CE58000A9EB8D /* Assets.xcassets in Resources */, 157 | B58BBB89215CE58000A9EB8D /* Main.storyboard in Resources */, 158 | ); 159 | runOnlyForDeploymentPostprocessing = 0; 160 | }; 161 | /* End PBXResourcesBuildPhase section */ 162 | 163 | /* Begin PBXSourcesBuildPhase section */ 164 | B58BBB7C215CE58000A9EB8D /* Sources */ = { 165 | isa = PBXSourcesBuildPhase; 166 | buildActionMask = 2147483647; 167 | files = ( 168 | B58BBB86215CE58000A9EB8D /* ViewController.swift in Sources */, 169 | B58BBB84215CE58000A9EB8D /* AppDelegate.swift in Sources */, 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | }; 173 | /* End PBXSourcesBuildPhase section */ 174 | 175 | /* Begin PBXVariantGroup section */ 176 | B58BBB87215CE58000A9EB8D /* Main.storyboard */ = { 177 | isa = PBXVariantGroup; 178 | children = ( 179 | B58BBB88215CE58000A9EB8D /* Base */, 180 | ); 181 | name = Main.storyboard; 182 | sourceTree = ""; 183 | }; 184 | B58BBB8C215CE58000A9EB8D /* LaunchScreen.storyboard */ = { 185 | isa = PBXVariantGroup; 186 | children = ( 187 | B58BBB8D215CE58000A9EB8D /* Base */, 188 | ); 189 | name = LaunchScreen.storyboard; 190 | sourceTree = ""; 191 | }; 192 | /* End PBXVariantGroup section */ 193 | 194 | /* Begin XCBuildConfiguration section */ 195 | B58BBB90215CE58000A9EB8D /* Debug */ = { 196 | isa = XCBuildConfiguration; 197 | buildSettings = { 198 | ALWAYS_SEARCH_USER_PATHS = NO; 199 | CLANG_ANALYZER_NONNULL = YES; 200 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_ENABLE_MODULES = YES; 204 | CLANG_ENABLE_OBJC_ARC = YES; 205 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 206 | CLANG_WARN_BOOL_CONVERSION = YES; 207 | CLANG_WARN_COMMA = YES; 208 | CLANG_WARN_CONSTANT_CONVERSION = YES; 209 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 210 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 211 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 212 | CLANG_WARN_EMPTY_BODY = YES; 213 | CLANG_WARN_ENUM_CONVERSION = YES; 214 | CLANG_WARN_INFINITE_RECURSION = YES; 215 | CLANG_WARN_INT_CONVERSION = YES; 216 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 217 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 220 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 221 | CLANG_WARN_STRICT_PROTOTYPES = YES; 222 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 223 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 224 | CLANG_WARN_UNREACHABLE_CODE = YES; 225 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 226 | CODE_SIGN_IDENTITY = "iPhone Developer"; 227 | COPY_PHASE_STRIP = NO; 228 | DEBUG_INFORMATION_FORMAT = dwarf; 229 | ENABLE_STRICT_OBJC_MSGSEND = YES; 230 | ENABLE_TESTABILITY = YES; 231 | GCC_C_LANGUAGE_STANDARD = gnu11; 232 | GCC_DYNAMIC_NO_PIC = NO; 233 | GCC_NO_COMMON_BLOCKS = YES; 234 | GCC_OPTIMIZATION_LEVEL = 0; 235 | GCC_PREPROCESSOR_DEFINITIONS = ( 236 | "DEBUG=1", 237 | "$(inherited)", 238 | ); 239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 241 | GCC_WARN_UNDECLARED_SELECTOR = YES; 242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 243 | GCC_WARN_UNUSED_FUNCTION = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 246 | MTL_ENABLE_DEBUG_INFO = YES; 247 | ONLY_ACTIVE_ARCH = YES; 248 | SDKROOT = iphoneos; 249 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 250 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 251 | }; 252 | name = Debug; 253 | }; 254 | B58BBB91215CE58000A9EB8D /* Release */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | ALWAYS_SEARCH_USER_PATHS = NO; 258 | CLANG_ANALYZER_NONNULL = YES; 259 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_COMMA = YES; 267 | CLANG_WARN_CONSTANT_CONVERSION = YES; 268 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INFINITE_RECURSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 276 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 277 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 280 | CLANG_WARN_STRICT_PROTOTYPES = YES; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | CODE_SIGN_IDENTITY = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = gnu11; 291 | GCC_NO_COMMON_BLOCKS = YES; 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 299 | MTL_ENABLE_DEBUG_INFO = NO; 300 | SDKROOT = iphoneos; 301 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 302 | VALIDATE_PRODUCT = YES; 303 | }; 304 | name = Release; 305 | }; 306 | B58BBB93215CE58000A9EB8D /* Debug */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | CODE_SIGN_STYLE = Automatic; 311 | DEVELOPMENT_TEAM = S6RF4D9458; 312 | INFOPLIST_FILE = Example/Info.plist; 313 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 314 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 315 | PRODUCT_BUNDLE_IDENTIFIER = zy.ZYNavigationBar.example; 316 | PRODUCT_NAME = ZYNavigationBarExample; 317 | SWIFT_VERSION = 5.0; 318 | TARGETED_DEVICE_FAMILY = "1,2"; 319 | }; 320 | name = Debug; 321 | }; 322 | B58BBB94215CE58000A9EB8D /* Release */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 326 | CODE_SIGN_STYLE = Automatic; 327 | DEVELOPMENT_TEAM = S6RF4D9458; 328 | INFOPLIST_FILE = Example/Info.plist; 329 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 330 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 331 | PRODUCT_BUNDLE_IDENTIFIER = zy.ZYNavigationBar.example; 332 | PRODUCT_NAME = ZYNavigationBarExample; 333 | SWIFT_VERSION = 5.0; 334 | TARGETED_DEVICE_FAMILY = "1,2"; 335 | }; 336 | name = Release; 337 | }; 338 | /* End XCBuildConfiguration section */ 339 | 340 | /* Begin XCConfigurationList section */ 341 | B58BBB7B215CE58000A9EB8D /* Build configuration list for PBXProject "Example" */ = { 342 | isa = XCConfigurationList; 343 | buildConfigurations = ( 344 | B58BBB90215CE58000A9EB8D /* Debug */, 345 | B58BBB91215CE58000A9EB8D /* Release */, 346 | ); 347 | defaultConfigurationIsVisible = 0; 348 | defaultConfigurationName = Release; 349 | }; 350 | B58BBB92215CE58000A9EB8D /* Build configuration list for PBXNativeTarget "Example" */ = { 351 | isa = XCConfigurationList; 352 | buildConfigurations = ( 353 | B58BBB93215CE58000A9EB8D /* Debug */, 354 | B58BBB94215CE58000A9EB8D /* Release */, 355 | ); 356 | defaultConfigurationIsVisible = 0; 357 | defaultConfigurationName = Release; 358 | }; 359 | /* End XCConfigurationList section */ 360 | }; 361 | rootObject = B58BBB78215CE58000A9EB8D /* Project object */; 362 | } 363 | -------------------------------------------------------------------------------- /Source/ZYNavigationController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZYNavigationController.swift 3 | // ZYNavigationBar 4 | // 5 | // Created by yu zhou on 11/09/2018. 6 | // Copyright © 2018 yu zhou. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class ZYNavigationController: UINavigationController { 12 | var inGesture = false 13 | 14 | var fromFakeBar: UIVisualEffectView = { 15 | return UIVisualEffectView(effect: UIBlurEffect.init(style: .light)) 16 | }() 17 | var toFakeBar: UIVisualEffectView = { 18 | return UIVisualEffectView(effect: UIBlurEffect.init(style: .light)) 19 | }() 20 | var fromFakeImageView: UIImageView = { 21 | return UIImageView() 22 | }() 23 | var toFakeImageView: UIImageView = { 24 | return UIImageView() 25 | }() 26 | lazy var fromFakeShadow: UIImageView = { 27 | let v = UIImageView(image: self.zy_navigationBar.shadowImageView.image) 28 | v.backgroundColor = self.zy_navigationBar.shadowImageView.backgroundColor 29 | return v 30 | }() 31 | lazy var toFakeShadow: UIImageView = { 32 | let v = UIImageView(image: self.zy_navigationBar.shadowImageView.image) 33 | v.backgroundColor = self.zy_navigationBar.shadowImageView.backgroundColor 34 | return v 35 | }() 36 | 37 | var zy_navigationBar: ZYNavigationBar { 38 | return self.navigationBar as! ZYNavigationBar 39 | } 40 | 41 | public override init(rootViewController: UIViewController) { 42 | super.init(navigationBarClass: ZYNavigationBar.classForCoder(), toolbarClass: nil) 43 | super.viewControllers = [rootViewController] 44 | } 45 | public override init(navigationBarClass: AnyClass?, toolbarClass: AnyClass?) { 46 | guard let isSubclass = navigationBarClass?.isSubclass(of: ZYNavigationBar.self), isSubclass == true else { 47 | fatalError("navigationBarClass must be ZYNavigationBar") 48 | } 49 | super.init(navigationBarClass: navigationBarClass, toolbarClass: toolbarClass) 50 | } 51 | 52 | public init() { 53 | super.init(navigationBarClass: ZYNavigationBar.self, toolbarClass: nil) 54 | } 55 | public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { 56 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) 57 | } 58 | public required init?(coder aDecoder: NSCoder) { 59 | super.init(coder: aDecoder) 60 | } 61 | 62 | public override func viewDidLoad() { 63 | super.viewDidLoad() 64 | self.interactivePopGestureRecognizer?.delegate = self 65 | self.interactivePopGestureRecognizer?.addTarget(self, action: #selector(handlePopGesture(recognizer:))) 66 | self.delegate = self 67 | self.zy_navigationBar.isTranslucent = true 68 | self.zy_navigationBar.shadowImageView.backgroundColor = UIColor.black.withAlphaComponent(0.3) 69 | } 70 | 71 | func fakeBarFrameForViewController(_ vc:UIViewController) -> CGRect { 72 | let backgroundFrame = self.zy_navigationBar.subviews.first!.frame 73 | var frame = self.zy_navigationBar.convert(backgroundFrame, to: vc.view) 74 | frame.origin.x = vc.view.frame.origin.x 75 | if vc.view.isKind(of: UIScrollView.self) { 76 | frame.origin.y = -(UIScreen.main.bounds.height == 812.0 ? 88 : 64) 77 | } 78 | return frame 79 | } 80 | 81 | func fakeShadowFrameWithBarFrame(frame:CGRect) -> CGRect { 82 | return CGRect(x: frame.origin.x, y: frame.height+frame.origin.y-0.5, width: frame.width, height: 0.5) 83 | } 84 | 85 | func removeFakeView() { 86 | fromFakeBar.removeFromSuperview() 87 | fromFakeShadow.removeFromSuperview() 88 | fromFakeImageView.removeFromSuperview() 89 | toFakeShadow.removeFromSuperview() 90 | toFakeBar.removeFromSuperview() 91 | toFakeImageView.removeFromSuperview() 92 | } 93 | 94 | func updateNavigationBarForViewController(controller:UIViewController) { 95 | self.updateNavigationBarAnimatedForController(controller) 96 | self.updateNavigationBarAlphaForViewController(controller) 97 | self.updateNavigationBarShadowAlphaForViewController(controller) 98 | self.updateNavigationBarColorOrImageForViewController(controller) 99 | } 100 | 101 | /// update target controller barStyle 102 | /// 103 | /// - Parameter controller: targetController 104 | func updateNavigationBarAnimatedForController(_ controller:UIViewController) { 105 | self.zy_navigationBar.barStyle = controller.zy_barStyle 106 | self.zy_navigationBar.titleTextAttributes = controller.zy_titleTextAttributes 107 | self.zy_navigationBar.tintColor = controller.zy_tintColor 108 | } 109 | 110 | /// update target controller barAlpha and shadowAlpha 111 | /// 112 | /// - Parameter controller: 113 | func updateNavigationBarAlphaForViewController(_ controller:UIViewController) { 114 | if controller.zy_computedBarImage != nil { 115 | self.zy_navigationBar.fakeView.alpha = 0 116 | self.zy_navigationBar.backgroundImageView.alpha = controller.zy_barAlpha 117 | } else { 118 | self.zy_navigationBar.fakeView.alpha = controller.zy_barAlpha 119 | self.zy_navigationBar.backgroundImageView.alpha = 0 120 | } 121 | self.zy_navigationBar.shadowImageView.alpha = controller.zy_computedBarShadowAlpha 122 | } 123 | 124 | func updateNavigationBarColorOrImageForViewController(_ controller:UIViewController) { 125 | self.zy_navigationBar.barTintColor = controller.zy_computedBarTintColor 126 | self.zy_navigationBar.backgroundImageView.image = controller.zy_computedBarImage 127 | } 128 | 129 | func updateNavigationBarShadowAlphaForViewController(_ controller:UIViewController) { 130 | self.zy_navigationBar.shadowImageView.alpha = controller.zy_computedBarShadowAlpha 131 | } 132 | 133 | public override func popViewController(animated: Bool) -> UIViewController? { 134 | guard let vc = self.topViewController else { return nil } 135 | let pVC = super.popViewController(animated: animated) 136 | self.zy_navigationBar.barStyle = vc.zy_barStyle 137 | self.zy_navigationBar.titleTextAttributes = vc.zy_titleTextAttributes 138 | return pVC 139 | } 140 | public override func popToRootViewController(animated: Bool) -> [UIViewController]? { 141 | guard let vc = self.topViewController else { return nil } 142 | let pVC = super.popToRootViewController(animated: animated) 143 | self.zy_navigationBar.barStyle = vc.zy_barStyle 144 | self.zy_navigationBar.titleTextAttributes = vc.zy_titleTextAttributes 145 | return pVC 146 | } 147 | public override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? { 148 | guard let vc = self.topViewController else { return nil } 149 | let pVCs = super.popToViewController(viewController, animated: animated) 150 | self.zy_navigationBar.barStyle = vc.zy_barStyle 151 | self.zy_navigationBar.titleTextAttributes = vc.zy_titleTextAttributes 152 | return pVCs 153 | } 154 | } 155 | 156 | // MARK: - UIGestureRecognizerDelegate 157 | extension ZYNavigationController:UIGestureRecognizerDelegate { 158 | @objc func handlePopGesture(recognizer: UIScreenEdgePanGestureRecognizer) { 159 | guard let coordinator = self.transitionCoordinator, 160 | let fromVC = coordinator.viewController(forKey: .from), 161 | let toVC = coordinator.viewController(forKey: .to) 162 | else { return } 163 | 164 | if recognizer.state == .began || recognizer.state == .changed { 165 | self.inGesture = true 166 | self.zy_navigationBar.tintColor = self.blendColor(from: fromVC.zy_tintColor, to: toVC.zy_tintColor, percent: coordinator.percentComplete) 167 | }else{ 168 | self.inGesture = false 169 | } 170 | } 171 | 172 | public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 173 | guard let vc = self.topViewController else { return false} 174 | return self.viewControllers.count > 1 ? (vc.zy_backInteractive && vc.zy_swipeBackEnabled) : false 175 | } 176 | } 177 | 178 | // MARK: - UINavigationControllerDelegate 179 | extension ZYNavigationController: UINavigationControllerDelegate{ 180 | public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) { 181 | guard let coordinator = self.transitionCoordinator, 182 | let fromVC = coordinator.viewController(forKey: .from), 183 | let toVC = coordinator.viewController(forKey: .to) 184 | else { self.updateNavigationBarForViewController(controller: viewController); return } 185 | 186 | coordinator.animate(alongsideTransition: { (context) in 187 | guard self.shouldShowFake(vc: viewController, from: fromVC, to: toVC) else { return } 188 | self.updateNavigationBarAnimatedForController(viewController) 189 | UIView.performWithoutAnimation { 190 | self.zy_navigationBar.fakeView.alpha = 0 191 | self.zy_navigationBar.shadowImageView.alpha = 0 192 | self.zy_navigationBar.backgroundImageView.alpha = 0 193 | 194 | //from 195 | self.fromFakeImageView.image = fromVC.zy_computedBarImage 196 | self.fromFakeImageView.alpha = fromVC.zy_barAlpha 197 | self.fromFakeImageView.frame = self.fakeBarFrameForViewController(fromVC) 198 | fromVC.view.addSubview(self.fromFakeImageView) 199 | 200 | self.fromFakeBar.subviews.last?.backgroundColor = fromVC.zy_computedBarTintColor 201 | self.fromFakeBar.alpha = (fromVC.zy_barAlpha == 0 || fromVC.zy_computedBarImage != nil) ? 0.01:fromVC.zy_barAlpha 202 | self.fromFakeBar.frame = self.fakeBarFrameForViewController(fromVC) 203 | fromVC.view.addSubview(self.fromFakeBar) 204 | 205 | self.fromFakeShadow.alpha = fromVC.zy_computedBarShadowAlpha 206 | self.fromFakeShadow.frame = self.fakeShadowFrameWithBarFrame(frame: self.fakeBarFrameForViewController(fromVC)) 207 | fromVC.view.addSubview(self.fromFakeShadow) 208 | 209 | // //to 210 | self.toFakeImageView.image = toVC.zy_computedBarImage 211 | self.toFakeImageView.alpha = toVC.zy_barAlpha 212 | self.toFakeImageView.frame = self.fakeBarFrameForViewController(toVC) 213 | toVC.view.addSubview(self.toFakeImageView) 214 | 215 | self.toFakeBar.subviews.last?.backgroundColor = toVC.zy_computedBarTintColor 216 | self.toFakeBar.alpha = toVC.zy_computedBarImage != nil ? 0 : toVC.zy_barAlpha 217 | self.toFakeBar.frame = self.fakeBarFrameForViewController(toVC) 218 | toVC.view.addSubview(self.toFakeBar) 219 | 220 | self.toFakeShadow.alpha = toVC.zy_computedBarShadowAlpha 221 | self.toFakeShadow.frame = self.fakeShadowFrameWithBarFrame(frame: self.fakeBarFrameForViewController(toVC)) 222 | toVC.view.addSubview(self.toFakeShadow) 223 | } 224 | }) { (context) in 225 | context.isCancelled ? self.updateNavigationBarForViewController(controller: fromVC) : self.updateNavigationBarForViewController(controller: viewController) 226 | if toVC == viewController { 227 | self.removeFakeView() 228 | } 229 | //解决iOS10及以下,在barIshidden的页面侧滑返回取消时 出现神奇的“...”在navigationBar上 230 | if #available(iOS 11.0, *){ 231 | }else{ 232 | if context.isCancelled { 233 | let buttItemView = self.navigationBar.subviews.filter { (v) -> Bool in 234 | return "\(type(of: v))" == "UINavigationItemButtonView" 235 | } 236 | buttItemView.first?.isHidden = fromVC.zy_barIsHidden 237 | } 238 | } 239 | } 240 | } 241 | } 242 | 243 | // MARK: - UINavigationBarDelegate 244 | extension ZYNavigationController: UINavigationBarDelegate { 245 | public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool { 246 | guard let topVC = self.topViewController else { return false } 247 | if self.viewControllers.count > 1 && topVC.navigationItem == item{ 248 | if topVC.zy_backInteractive == false { 249 | self.resetNavBarSubViews(navBar: self.zy_navigationBar) 250 | return false 251 | } 252 | } 253 | if !inGesture { 254 | _ = self.popViewController(animated: true) 255 | } 256 | return true 257 | } 258 | func resetNavBarSubViews(navBar: UINavigationBar) { 259 | if #available(iOS 11, *) { 260 | }else{ 261 | for v in navBar.subviews { 262 | if v.alpha < 1.0 { 263 | UIView.animate(withDuration: 0.25, animations: { 264 | v.alpha = 1 265 | }) 266 | } 267 | } 268 | } 269 | 270 | } 271 | } 272 | 273 | // MARK: - Tool 274 | extension ZYNavigationController { 275 | 276 | /// 计算两种颜色的中间色 277 | /// 278 | /// - Parameters: 279 | /// - from: <#from description#> 280 | /// - to: <#to description#> 281 | /// - percent: <#percent description#> 282 | /// - Returns: <#return value description#> 283 | func blendColor(from:UIColor,to:UIColor,percent:CGFloat) -> UIColor { 284 | var fromRed: CGFloat = 0 285 | var fromGreen: CGFloat = 0 286 | var fromBlue: CGFloat = 0 287 | var fromAlpha: CGFloat = 0 288 | from.getRed(&fromRed, green: &fromGreen, blue: &fromBlue, alpha: &fromAlpha) 289 | 290 | var toRed: CGFloat = 0 291 | var toGreen: CGFloat = 0 292 | var toBlue: CGFloat = 0 293 | var toAlpha: CGFloat = 0 294 | to.getRed(&toRed, green: &toGreen, blue: &toBlue, alpha: &toAlpha) 295 | 296 | let nRed = fromRed + (toRed - fromRed) * percent 297 | let nGreen = fromGreen + (toGreen - fromGreen) * percent 298 | let nBlue = fromBlue + (toBlue - fromBlue) * percent 299 | let nAlpha = fromAlpha + (toAlpha - fromAlpha) * percent 300 | 301 | return UIColor(red: nRed, green: nGreen, blue: nBlue, alpha: nAlpha) 302 | } 303 | 304 | /// 判断navbar的状态是否相同,用于是否进行动画的判断 305 | /// 306 | /// - Parameters: 307 | /// - vc: <#vc description#> 308 | /// - from: <#from description#> 309 | /// - to: <#to description#> 310 | /// - Returns: <#return value description#> 311 | func shouldShowFake(vc: UIViewController,from: UIViewController, to:UIViewController) -> Bool { 312 | guard vc == to else { return false } 313 | if from.zy_computedBarImage != nil && 314 | to.zy_computedBarImage != nil && 315 | isEqualImage(from.zy_computedBarImage!, to.zy_computedBarImage!) { 316 | if abs(from.zy_barAlpha - to.zy_barAlpha) > 0.1 { 317 | return true 318 | } 319 | return false 320 | } 321 | 322 | if from.zy_computedBarImage == nil && 323 | to.zy_computedBarImage == nil && 324 | from.zy_computedBarTintColor?.description == to.zy_computedBarTintColor?.description { 325 | if abs(from.zy_barAlpha - to.zy_barAlpha) > 0.1 { 326 | return true 327 | } 328 | return false 329 | } 330 | return true 331 | } 332 | 333 | /// 比较两个image是否相同 334 | /// 335 | /// - Parameters: 336 | /// - image1: <#image1 description#> 337 | /// - image2: <#image2 description#> 338 | /// - Returns: <#return value description#> 339 | func isEqualImage(_ image1:UIImage,_ image2:UIImage) -> Bool { 340 | guard image1 != image2 else { return true } 341 | let data1 = image1.pngData() 342 | let data2 = image2.pngData() 343 | 344 | return data1 == data2 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 63 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | --------------------------------------------------------------------------------