diff --git a/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json index eeea76c..1d060ed 100644 --- a/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index fadb03c..47c0abd 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -13,7 +13,7 @@ - + @@ -27,10 +27,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -59,7 +108,7 @@ - + @@ -215,6 +264,11 @@ + + + + + diff --git a/Example/DisableTransitionNavigationController.swift b/Example/DisableTransitionNavigationController.swift new file mode 100644 index 0000000..fea5c63 --- /dev/null +++ b/Example/DisableTransitionNavigationController.swift @@ -0,0 +1,27 @@ +// +// DisableTransitionNavigationController.swift +// KMNavigationBarTransition +// +// Created by Wilson Yuan on 2017/6/21. +// Copyright © 2017年 Zhouqi Mo. All rights reserved. +// + +import UIKit + +class DisableTransitionNavigationController: UINavigationController { + + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + self.km_disableTransition = true + } + + override init(rootViewController: UIViewController) { + super.init(rootViewController: rootViewController) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + self.km_disableTransition = true + } + +} diff --git a/Example/KMNavigationBarTransition-Bridge-Header.h b/Example/KMNavigationBarTransition-Bridge-Header.h new file mode 100644 index 0000000..0b79d2f --- /dev/null +++ b/Example/KMNavigationBarTransition-Bridge-Header.h @@ -0,0 +1,14 @@ +// +// KMNavigationBarTransition-Bridge-Header.h +// KMNavigationBarTransition +// +// Created by Wilson Yuan on 2017/6/21. +// Copyright © 2017年 Zhouqi Mo. All rights reserved. +// + +#ifndef KMNavigationBarTransition_Bridge_Header_h +#define KMNavigationBarTransition_Bridge_Header_h + +#import + +#endif /* KMNavigationBarTransition_Bridge_Header_h */ diff --git a/Example/MainViewController.swift b/Example/MainViewController.swift index 9066fbd..b711b09 100644 --- a/Example/MainViewController.swift +++ b/Example/MainViewController.swift @@ -55,6 +55,13 @@ class MainViewController: UITableViewController { navigationController?.setNavigationBarHidden(currentNavigationBarData.prefersHidden, animated: animated) } + @IBAction func presentBarButtonAction(_ sender: Any) { + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PresentViewController.self)) + let controller = storyboard.instantiateViewController(withIdentifier: "PresentViewController") + let navigation = NavigationController(rootViewController: controller) + self.present(navigation, animated: true, completion: nil) + } + } // MARK: - Target Action diff --git a/Example/NavigationController.swift b/Example/NavigationController.swift index d183a14..66f0192 100644 --- a/Example/NavigationController.swift +++ b/Example/NavigationController.swift @@ -11,7 +11,6 @@ import UIKit class NavigationController: UINavigationController { // MARK: View Life Cycle - override func viewDidLoad() { super.viewDidLoad() self.interactivePopGestureRecognizer?.delegate = self diff --git a/Example/PresentViewController.swift b/Example/PresentViewController.swift new file mode 100644 index 0000000..80177ca --- /dev/null +++ b/Example/PresentViewController.swift @@ -0,0 +1,78 @@ +// +// PresentViewController.swift +// KMNavigationBarTransition +// +// Created by Wilson Yuan on 2017/6/21. +// Copyright © 2017年 Zhouqi Mo. All rights reserved. +// + +import UIKit + +class PresentViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.leftBarButtonAction)) + + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "next", style: .plain, target: self, action: #selector(self.rightBarButtonAction)) + + } + +} + +///Action +extension PresentViewController { + + func leftBarButtonAction() { + if self.navigationController!.viewControllers.count == 1 { + self.dismiss(animated: true, completion: nil) + } + else { + self.navigationController?.popViewController(animated: true) + } + } + + func rightBarButtonAction() { + let controller = presentViewController() + controller.km_disableTransition = true + self.show(controller, sender: nil) + } + + @IBAction func popToRootAction(_ sender: Any) { + self.navigationController?.popToRootViewController(animated: true) + } + + @IBAction func popToPenultAction(_ sender: Any) { + + guard let navigation = self.navigationController, + navigation.viewControllers.count > 2 else { + print("current view controllers count: \(String(describing: self.navigationController?.viewControllers.count))") + return + } + + let controller = navigation.viewControllers[navigation.viewControllers.count - 3] + self.navigationController?.popToViewController(controller, animated: true) + } + + @IBAction func setControllersAction(_ sender: Any) { + + let controller = presentViewController() + controller.view.backgroundColor = UIColor.red + let blueController = presentViewController() + blueController.view.backgroundColor = UIColor.blue + let controllers = [controller, blueController] + + self.navigationController?.setViewControllers(controllers, animated: false) + } +} + +/// Private method +extension PresentViewController { + fileprivate func presentViewController() -> PresentViewController { + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PresentViewController.self)) + let controller = storyboard.instantiateViewController(withIdentifier: "PresentViewController") + return controller as! PresentViewController + } +} diff --git a/KMNavigationBarTransition.xcodeproj/project.pbxproj b/KMNavigationBarTransition.xcodeproj/project.pbxproj index 1d8f4b7..7d75e1c 100644 --- a/KMNavigationBarTransition.xcodeproj/project.pbxproj +++ b/KMNavigationBarTransition.xcodeproj/project.pbxproj @@ -7,21 +7,24 @@ objects = { /* Begin PBXBuildFile section */ - CDA372851C39087D00E39A6D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372841C39087D00E39A6D /* AppDelegate.swift */; }; - CDA372881C39089200E39A6D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CDA372861C39089200E39A6D /* Main.storyboard */; }; - CDA3728A1C39089900E39A6D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDA372891C39089900E39A6D /* Assets.xcassets */; }; - CDA3728D1C3908A000E39A6D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CDA3728B1C3908A000E39A6D /* LaunchScreen.storyboard */; }; - CDA372951C39093E00E39A6D /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372901C39093E00E39A6D /* MainViewController.swift */; }; - CDA372961C39093E00E39A6D /* NavigationBarData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372911C39093E00E39A6D /* NavigationBarData.swift */; }; - CDA372971C39093E00E39A6D /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372921C39093E00E39A6D /* NavigationController.swift */; }; - CDA372981C39093E00E39A6D /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372931C39093E00E39A6D /* SettingsViewController.swift */; }; - CDA372991C39093E00E39A6D /* UIImage+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA372941C39093E00E39A6D /* UIImage+Color.swift */; }; + C851C0851EFB68B400A99AEA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0761EFB68B400A99AEA /* AppDelegate.swift */; }; + C851C0861EFB68B400A99AEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C851C0771EFB68B400A99AEA /* Assets.xcassets */; }; + C851C0871EFB68B400A99AEA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C851C0781EFB68B400A99AEA /* LaunchScreen.storyboard */; }; + C851C0881EFB68B400A99AEA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C851C07A1EFB68B400A99AEA /* Main.storyboard */; }; + C851C0891EFB68B400A99AEA /* DisableTransitionNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C07C1EFB68B400A99AEA /* DisableTransitionNavigationController.swift */; }; + C851C08A1EFB68B400A99AEA /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C851C07D1EFB68B400A99AEA /* Info.plist */; }; + C851C08B1EFB68B400A99AEA /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C07F1EFB68B400A99AEA /* MainViewController.swift */; }; + C851C08C1EFB68B400A99AEA /* NavigationBarData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0801EFB68B400A99AEA /* NavigationBarData.swift */; }; + C851C08D1EFB68B400A99AEA /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0811EFB68B400A99AEA /* NavigationController.swift */; }; + C851C08E1EFB68B400A99AEA /* PresentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0821EFB68B400A99AEA /* PresentViewController.swift */; }; + C851C08F1EFB68B400A99AEA /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0831EFB68B400A99AEA /* SettingsViewController.swift */; }; + C851C0901EFB68B400A99AEA /* UIImage+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = C851C0841EFB68B400A99AEA /* UIImage+Color.swift */; }; CDAA3BB31E5CB40E00666BB0 /* UIViewController+KMNavigationBarTransition_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAA3BB21E5CB40E00666BB0 /* UIViewController+KMNavigationBarTransition_internal.h */; }; CDC01B971E5CA42000F6F3E2 /* KMNavigationBarTransition.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDC01B901E5CA42000F6F3E2 /* KMNavigationBarTransition.framework */; }; CDC01B981E5CA42000F6F3E2 /* KMNavigationBarTransition.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CDC01B901E5CA42000F6F3E2 /* KMNavigationBarTransition.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; CDC01B9D1E5CA46400F6F3E2 /* KMNavigationBarTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC01B9C1E5CA46400F6F3E2 /* KMNavigationBarTransition.h */; settings = {ATTRIBUTES = (Public, ); }; }; CDC01B9F1E5CA48400F6F3E2 /* UINavigationController+KMNavigationBarTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDFA1F31C3921BD00BFBA1B /* UINavigationController+KMNavigationBarTransition.h */; settings = {ATTRIBUTES = (Public, ); }; }; - CDC01BA11E5CA48900F6F3E2 /* UIViewController+KMNavigationBarTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDFA1F51C3921BD00BFBA1B /* UIViewController+KMNavigationBarTransition.h */; }; + CDC01BA11E5CA48900F6F3E2 /* UIViewController+KMNavigationBarTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = CDDFA1F51C3921BD00BFBA1B /* UIViewController+KMNavigationBarTransition.h */; settings = {ATTRIBUTES = (Public, ); }; }; CDC01BA21E5CA48B00F6F3E2 /* UIViewController+KMNavigationBarTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = CDDFA1F61C3921BD00BFBA1B /* UIViewController+KMNavigationBarTransition.m */; }; CDC01BA31E5CA48D00F6F3E2 /* KMWeakObjectContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC1BA0C1CE1DFE8006BE1B6 /* KMWeakObjectContainer.h */; }; CDC01BA41E5CA48F00F6F3E2 /* KMWeakObjectContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = CDC1BA0D1CE1DFE8006BE1B6 /* KMWeakObjectContainer.m */; }; @@ -56,17 +59,20 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + C851C0761EFB68B400A99AEA /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + C851C0771EFB68B400A99AEA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C851C0791EFB68B400A99AEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + C851C07B1EFB68B400A99AEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + C851C07C1EFB68B400A99AEA /* DisableTransitionNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisableTransitionNavigationController.swift; sourceTree = ""; }; + C851C07D1EFB68B400A99AEA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C851C07E1EFB68B400A99AEA /* KMNavigationBarTransition-Bridge-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KMNavigationBarTransition-Bridge-Header.h"; sourceTree = ""; }; + C851C07F1EFB68B400A99AEA /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; + C851C0801EFB68B400A99AEA /* NavigationBarData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarData.swift; sourceTree = ""; }; + C851C0811EFB68B400A99AEA /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = ""; }; + C851C0821EFB68B400A99AEA /* PresentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentViewController.swift; sourceTree = ""; }; + C851C0831EFB68B400A99AEA /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; + C851C0841EFB68B400A99AEA /* UIImage+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Color.swift"; sourceTree = ""; }; CDA3726F1C3907CE00E39A6D /* KMNavigationBarTransition-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "KMNavigationBarTransition-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - CDA372841C39087D00E39A6D /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = Example/AppDelegate.swift; sourceTree = SOURCE_ROOT; }; - CDA372871C39089200E39A6D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Example/Base.lproj/Main.storyboard; sourceTree = SOURCE_ROOT; }; - CDA372891C39089900E39A6D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Example/Assets.xcassets; sourceTree = SOURCE_ROOT; }; - CDA3728C1C3908A000E39A6D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Example/Base.lproj/LaunchScreen.storyboard; sourceTree = SOURCE_ROOT; }; - CDA3728E1C3908A500E39A6D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Example/Info.plist; sourceTree = SOURCE_ROOT; }; - CDA372901C39093E00E39A6D /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MainViewController.swift; path = Example/MainViewController.swift; sourceTree = SOURCE_ROOT; }; - CDA372911C39093E00E39A6D /* NavigationBarData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavigationBarData.swift; path = Example/NavigationBarData.swift; sourceTree = SOURCE_ROOT; }; - CDA372921C39093E00E39A6D /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NavigationController.swift; path = Example/NavigationController.swift; sourceTree = SOURCE_ROOT; }; - CDA372931C39093E00E39A6D /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsViewController.swift; path = Example/SettingsViewController.swift; sourceTree = SOURCE_ROOT; }; - CDA372941C39093E00E39A6D /* UIImage+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImage+Color.swift"; path = "Example/UIImage+Color.swift"; sourceTree = SOURCE_ROOT; }; CDAA3BB21E5CB40E00666BB0 /* UIViewController+KMNavigationBarTransition_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+KMNavigationBarTransition_internal.h"; sourceTree = ""; }; CDC01B901E5CA42000F6F3E2 /* KMNavigationBarTransition.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KMNavigationBarTransition.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CDC01B9C1E5CA46400F6F3E2 /* KMNavigationBarTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMNavigationBarTransition.h; sourceTree = ""; }; @@ -101,11 +107,31 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + C851C0751EFB68B400A99AEA /* Example */ = { + isa = PBXGroup; + children = ( + C851C07C1EFB68B400A99AEA /* DisableTransitionNavigationController.swift */, + C851C07F1EFB68B400A99AEA /* MainViewController.swift */, + C851C0801EFB68B400A99AEA /* NavigationBarData.swift */, + C851C0811EFB68B400A99AEA /* NavigationController.swift */, + C851C0821EFB68B400A99AEA /* PresentViewController.swift */, + C851C0831EFB68B400A99AEA /* SettingsViewController.swift */, + C851C0841EFB68B400A99AEA /* UIImage+Color.swift */, + C851C0761EFB68B400A99AEA /* AppDelegate.swift */, + C851C07E1EFB68B400A99AEA /* KMNavigationBarTransition-Bridge-Header.h */, + C851C0771EFB68B400A99AEA /* Assets.xcassets */, + C851C0781EFB68B400A99AEA /* LaunchScreen.storyboard */, + C851C07A1EFB68B400A99AEA /* Main.storyboard */, + C851C07D1EFB68B400A99AEA /* Info.plist */, + ); + path = Example; + sourceTree = ""; + }; CDA372661C3907CE00E39A6D = { isa = PBXGroup; children = ( CDDFA1F01C3921BD00BFBA1B /* KMNavigationBarTransition */, - CDA372711C3907CE00E39A6D /* Example */, + C851C0751EFB68B400A99AEA /* Example */, CDA372701C3907CE00E39A6D /* Products */, ); sourceTree = ""; @@ -119,40 +145,6 @@ name = Products; sourceTree = ""; }; - CDA372711C3907CE00E39A6D /* Example */ = { - isa = PBXGroup; - children = ( - CDA372861C39089200E39A6D /* Main.storyboard */, - CDA372901C39093E00E39A6D /* MainViewController.swift */, - CDA372931C39093E00E39A6D /* SettingsViewController.swift */, - CDA372921C39093E00E39A6D /* NavigationController.swift */, - CDA3729A1C39094600E39A6D /* Model */, - CDA3729B1C39094B00E39A6D /* Extension */, - CDA372841C39087D00E39A6D /* AppDelegate.swift */, - CDA372891C39089900E39A6D /* Assets.xcassets */, - CDA3728B1C3908A000E39A6D /* LaunchScreen.storyboard */, - CDA3728E1C3908A500E39A6D /* Info.plist */, - ); - name = Example; - path = KMNavigationBarTransition; - sourceTree = ""; - }; - CDA3729A1C39094600E39A6D /* Model */ = { - isa = PBXGroup; - children = ( - CDA372911C39093E00E39A6D /* NavigationBarData.swift */, - ); - name = Model; - sourceTree = ""; - }; - CDA3729B1C39094B00E39A6D /* Extension */ = { - isa = PBXGroup; - children = ( - CDA372941C39093E00E39A6D /* UIImage+Color.swift */, - ); - name = Extension; - sourceTree = ""; - }; CDDFA1F01C3921BD00BFBA1B /* KMNavigationBarTransition */ = { isa = PBXGroup; children = ( @@ -181,9 +173,9 @@ files = ( CDC01B9D1E5CA46400F6F3E2 /* KMNavigationBarTransition.h in Headers */, CDC01BAA1E5CA82800F6F3E2 /* UINavigationController+KMNavigationBarTransition_Internal.h in Headers */, + CDC01BA11E5CA48900F6F3E2 /* UIViewController+KMNavigationBarTransition.h in Headers */, CDAA3BB31E5CB40E00666BB0 /* UIViewController+KMNavigationBarTransition_internal.h in Headers */, CDC01B9F1E5CA48400F6F3E2 /* UINavigationController+KMNavigationBarTransition.h in Headers */, - CDC01BA11E5CA48900F6F3E2 /* UIViewController+KMNavigationBarTransition.h in Headers */, CDC01BA31E5CA48D00F6F3E2 /* KMWeakObjectContainer.h in Headers */, CDC01BA51E5CA49100F6F3E2 /* KMSwizzle.h in Headers */, ); @@ -273,9 +265,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - CDA3728D1C3908A000E39A6D /* LaunchScreen.storyboard in Resources */, - CDA3728A1C39089900E39A6D /* Assets.xcassets in Resources */, - CDA372881C39089200E39A6D /* Main.storyboard in Resources */, + C851C08A1EFB68B400A99AEA /* Info.plist in Resources */, + C851C0881EFB68B400A99AEA /* Main.storyboard in Resources */, + C851C0861EFB68B400A99AEA /* Assets.xcassets in Resources */, + C851C0871EFB68B400A99AEA /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -293,12 +286,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CDA372851C39087D00E39A6D /* AppDelegate.swift in Sources */, - CDA372971C39093E00E39A6D /* NavigationController.swift in Sources */, - CDA372951C39093E00E39A6D /* MainViewController.swift in Sources */, - CDA372981C39093E00E39A6D /* SettingsViewController.swift in Sources */, - CDA372961C39093E00E39A6D /* NavigationBarData.swift in Sources */, - CDA372991C39093E00E39A6D /* UIImage+Color.swift in Sources */, + C851C08B1EFB68B400A99AEA /* MainViewController.swift in Sources */, + C851C0901EFB68B400A99AEA /* UIImage+Color.swift in Sources */, + C851C08C1EFB68B400A99AEA /* NavigationBarData.swift in Sources */, + C851C08F1EFB68B400A99AEA /* SettingsViewController.swift in Sources */, + C851C08E1EFB68B400A99AEA /* PresentViewController.swift in Sources */, + C851C08D1EFB68B400A99AEA /* NavigationController.swift in Sources */, + C851C0851EFB68B400A99AEA /* AppDelegate.swift in Sources */, + C851C0891EFB68B400A99AEA /* DisableTransitionNavigationController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -324,20 +319,20 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - CDA372861C39089200E39A6D /* Main.storyboard */ = { + C851C0781EFB68B400A99AEA /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( - CDA372871C39089200E39A6D /* Base */, + C851C0791EFB68B400A99AEA /* Base */, ); - name = Main.storyboard; + name = LaunchScreen.storyboard; sourceTree = ""; }; - CDA3728B1C3908A000E39A6D /* LaunchScreen.storyboard */ = { + C851C07A1EFB68B400A99AEA /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( - CDA3728C1C3908A000E39A6D /* Base */, + C851C07B1EFB68B400A99AEA /* Base */, ); - name = LaunchScreen.storyboard; + name = Main.storyboard; sourceTree = ""; }; /* End PBXVariantGroup section */ @@ -440,6 +435,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.mo.KMNavigationBarTransition-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Example/KMNavigationBarTransition-Bridge-Header.h"; SWIFT_VERSION = 3.0; }; name = Debug; @@ -453,6 +449,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.mo.KMNavigationBarTransition-Example"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Example/KMNavigationBarTransition-Bridge-Header.h"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/KMNavigationBarTransition/KMNavigationBarTransition.h b/KMNavigationBarTransition/KMNavigationBarTransition.h index 190ba48..228529c 100644 --- a/KMNavigationBarTransition/KMNavigationBarTransition.h +++ b/KMNavigationBarTransition/KMNavigationBarTransition.h @@ -32,3 +32,4 @@ FOUNDATION_EXPORT const unsigned char KMNavigationBarTransitionVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import #import +#import diff --git a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.h b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.h index 8002a9a..fd8cc67 100755 --- a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.h +++ b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.h @@ -23,8 +23,12 @@ #import + @interface UINavigationController (KMNavigationBarTransition) +///disable the transition style +@property (nonatomic) BOOL km_disableTransition; + // By default this is white, it is related to issue with transparent navigationBar - (UIColor *)km_containerViewBackgroundColor; diff --git a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m index acae859..7e8a3ab 100755 --- a/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m +++ b/KMNavigationBarTransition/UINavigationController+KMNavigationBarTransition.m @@ -61,7 +61,13 @@ - (UIColor *)km_containerViewBackgroundColor { } - (void)km_pushViewController:(UIViewController *)viewController animated:(BOOL)animated { + if (self.km_disableTransition) { + return [self km_pushViewController:viewController animated:animated]; + } UIViewController *disappearingViewController = self.viewControllers.lastObject; + if (viewController.km_disableTransition && disappearingViewController.km_disableTransition) { + return [self km_pushViewController:viewController animated:animated]; + } if (!disappearingViewController) { return [self km_pushViewController:viewController animated:animated]; } @@ -78,12 +84,18 @@ - (void)km_pushViewController:(UIViewController *)viewController animated:(BOOL) } - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated { + if (self.km_disableTransition) { + return [self km_popViewControllerAnimated:animated]; + } if (self.viewControllers.count < 2) { return [self km_popViewControllerAnimated:animated]; } UIViewController *disappearingViewController = self.viewControllers.lastObject; - [disappearingViewController km_addTransitionNavigationBarIfNeeded]; UIViewController *appearingViewController = self.viewControllers[self.viewControllers.count - 2]; + if (disappearingViewController.km_disableTransition && appearingViewController.km_disableTransition) { + return [self km_popViewControllerAnimated:animated]; + } + [disappearingViewController km_addTransitionNavigationBarIfNeeded]; if (appearingViewController.km_transitionNavigationBar) { UINavigationBar *appearingNavigationBar = appearingViewController.km_transitionNavigationBar; self.navigationBar.barTintColor = appearingNavigationBar.barTintColor; @@ -95,12 +107,18 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated { } return [self km_popViewControllerAnimated:animated]; } - +///TODO: Test A0->B1->C0->1D - (NSArray *)km_popToViewController:(UIViewController *)viewController animated:(BOOL)animated { + if (self.km_disableTransition) { + return [self km_popToViewController:viewController animated:animated]; + } if (![self.viewControllers containsObject:viewController] || self.viewControllers.count < 2) { return [self km_popToViewController:viewController animated:animated]; } UIViewController *disappearingViewController = self.viewControllers.lastObject; + if (viewController.km_disableTransition && disappearingViewController.km_disableTransition) { + return [self km_popToViewController:viewController animated:animated]; + } [disappearingViewController km_addTransitionNavigationBarIfNeeded]; if (viewController.km_transitionNavigationBar) { UINavigationBar *appearingNavigationBar = viewController.km_transitionNavigationBar; @@ -115,12 +133,18 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated { } - (NSArray *)km_popToRootViewControllerAnimated:(BOOL)animated { + if (self.km_disableTransition) { + return [self km_popToRootViewControllerAnimated:animated]; + } if (self.viewControllers.count < 2) { return [self km_popToRootViewControllerAnimated:animated]; } UIViewController *disappearingViewController = self.viewControllers.lastObject; - [disappearingViewController km_addTransitionNavigationBarIfNeeded]; UIViewController *rootViewController = self.viewControllers.firstObject; + if (disappearingViewController.km_disableTransition && rootViewController.km_disableTransition) { + return [self km_popToRootViewControllerAnimated:animated]; + } + [disappearingViewController km_addTransitionNavigationBarIfNeeded]; if (rootViewController.km_transitionNavigationBar) { UINavigationBar *appearingNavigationBar = rootViewController.km_transitionNavigationBar; self.navigationBar.barTintColor = appearingNavigationBar.barTintColor; @@ -134,12 +158,27 @@ - (UIViewController *)km_popViewControllerAnimated:(BOOL)animated { } - (void)km_setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated { + if (self.km_disableTransition) { + return [self km_setViewControllers:viewControllers animated:animated]; + } UIViewController *disappearingViewController = self.viewControllers.lastObject; + UIViewController *appearingViewController = viewControllers.lastObject; + if (disappearingViewController.km_disableTransition && appearingViewController.km_disableTransition) { + return [self km_setViewControllers:viewControllers animated:animated]; + } if (animated && disappearingViewController && ![disappearingViewController isEqual:viewControllers.lastObject]) { [disappearingViewController km_addTransitionNavigationBarIfNeeded]; if (disappearingViewController.km_transitionNavigationBar) { disappearingViewController.km_prefersNavigationBarBackgroundViewHidden = YES; } + self.km_transitionContextToViewController = appearingViewController; + } + + for (UIViewController *controller in viewControllers) { + if (![controller isEqual:appearingViewController]) { + controller.km_isSetViewController = true; + [controller km_addTransitionNavigationBarIfNeeded]; + } } return [self km_setViewControllers:viewControllers animated:animated]; } @@ -152,4 +191,12 @@ - (void)setKm_transitionContextToViewController:(UIViewController *)viewControll km_objc_setAssociatedWeakObject(self, @selector(km_transitionContextToViewController), viewController); } +- (BOOL)km_disableTransition { + return [km_objc_getAssociatedWeakObject(self, _cmd) boolValue]; +} + +- (void)setKm_disableTransition:(BOOL)km_disableTransition { + km_objc_setAssociatedWeakObject(self, @selector(km_disableTransition), @(km_disableTransition)); +} + @end diff --git a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.h b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.h index 25e6a6a..92839ba 100644 --- a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.h +++ b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.h @@ -25,4 +25,7 @@ @interface UIViewController (KMNavigationBarTransition) +///disable the transition style +@property (nonatomic) BOOL km_disableTransition; + @end diff --git a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m index 16306d5..f821c74 100644 --- a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m +++ b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition.m @@ -24,6 +24,7 @@ #import "UIViewController+KMNavigationBarTransition.h" #import #import "KMSwizzle.h" +#import "KMWeakObjectContainer.h" #import "UINavigationController+KMNavigationBarTransition.h" #import "UINavigationController+KMNavigationBarTransition_Internal.h" @@ -63,8 +64,7 @@ - (void)km_viewWillLayoutSubviews { id tc = self.transitionCoordinator; UIViewController *fromViewController = [tc viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [tc viewControllerForKey:UITransitionContextToViewControllerKey]; - - if ([self isEqual:self.navigationController.viewControllers.lastObject] && [toViewController isEqual:self] && self.navigationController.km_transitionContextToViewController) { + if ([self isEqual:self.navigationController.viewControllers.lastObject] && [toViewController isEqual:self] && (self.navigationController.km_transitionContextToViewController || self.km_isSetViewController)) { if (self.navigationController.navigationBar.translucent) { [tc containerView].backgroundColor = [self.navigationController km_containerViewBackgroundColor]; } @@ -72,10 +72,10 @@ - (void)km_viewWillLayoutSubviews { toViewController.view.clipsToBounds = NO; if (!self.km_transitionNavigationBar) { [self km_addTransitionNavigationBarIfNeeded]; - self.km_prefersNavigationBarBackgroundViewHidden = YES; } [self km_resizeTransitionNavigationBarFrame]; + self.km_isSetViewController = NO; } if (self.km_transitionNavigationBar) { [self.view bringSubviewToFront:self.km_transitionNavigationBar]; @@ -106,8 +106,10 @@ - (void)km_addTransitionNavigationBarIfNeeded { bar.translucent = self.navigationController.navigationBar.translucent; } bar.barTintColor = self.navigationController.navigationBar.barTintColor; - [bar setBackgroundImage:[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault]; - bar.shadowImage = self.navigationController.navigationBar.shadowImage; + UIImage *backgroundImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault]; + [bar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; + UIImage *shadowImage = self.navigationController.navigationBar.shadowImage; + bar.shadowImage = shadowImage; [self.km_transitionNavigationBar removeFromSuperview]; self.km_transitionNavigationBar = bar; [self km_resizeTransitionNavigationBarFrame]; @@ -151,4 +153,21 @@ - (void)setKm_prefersNavigationBarBackgroundViewHidden:(BOOL)hidden { objc_setAssociatedObject(self, @selector(km_prefersNavigationBarBackgroundViewHidden), @(hidden), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +- (BOOL)km_disableTransition { + return [km_objc_getAssociatedWeakObject(self, _cmd) boolValue]; +} + +- (void)setKm_disableTransition:(BOOL)km_disableTransition { + km_objc_setAssociatedWeakObject(self, @selector(km_disableTransition), @(km_disableTransition)); +} + +- (BOOL)km_isSetViewController { + return [km_objc_getAssociatedWeakObject(self, _cmd) boolValue]; +} + +- (void)setKm_isSetViewController:(BOOL)km_isSetViewController { + km_objc_setAssociatedWeakObject(self, @selector(km_isSetViewController), @(km_isSetViewController)); +} + + @end diff --git a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition_internal.h b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition_internal.h index e34c0ec..c00746f 100644 --- a/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition_internal.h +++ b/KMNavigationBarTransition/UIViewController+KMNavigationBarTransition_internal.h @@ -27,6 +27,7 @@ @property (nonatomic, strong) UINavigationBar *km_transitionNavigationBar; @property (nonatomic, assign) BOOL km_prefersNavigationBarBackgroundViewHidden; +@property (nonatomic) BOOL km_isSetViewController; - (void)km_addTransitionNavigationBarIfNeeded;