├── .DS_Store ├── .gitignore ├── .swift-version ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── Info.plist │ ├── Screen.swift │ └── ViewController.swift ├── LICENSE ├── MMNavigationController.podspec ├── MMNavigationController.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── MMNavigationController.xcworkspace └── contents.xcworkspacedata ├── README.md └── Source ├── Info.plist ├── MMNavigationController.h ├── MMNavigationController.swift ├── Namespace.swift ├── PopGestrueDelegateObject.swift ├── UIViewControllerExtension.swift ├── ViewControllerInjectBlockWrapper.swift └── WeakReferenceWrapper.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MangoMade/MMNavigationController/89f68a04453f0b302647de058e6726a538e2be7f/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 525D0C431EA8B1BB00FF5844 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C421EA8B1BB00FF5844 /* AppDelegate.swift */; }; 11 | 525D0C451EA8B1BB00FF5844 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C441EA8B1BB00FF5844 /* ViewController.swift */; }; 12 | 525D0C4A1EA8B1BB00FF5844 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 525D0C491EA8B1BB00FF5844 /* Assets.xcassets */; }; 13 | 525D0C4D1EA8B1BB00FF5844 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 525D0C4B1EA8B1BB00FF5844 /* LaunchScreen.storyboard */; }; 14 | 525D0C651EA8B22E00FF5844 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C641EA8B22E00FF5844 /* Screen.swift */; }; 15 | 525D0C681EA8B31D00FF5844 /* MMNavigationController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525D0C671EA8B31D00FF5844 /* MMNavigationController.framework */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 525D0C3F1EA8B1BB00FF5844 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 525D0C421EA8B1BB00FF5844 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 525D0C441EA8B1BB00FF5844 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 525D0C491EA8B1BB00FF5844 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 525D0C4C1EA8B1BB00FF5844 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 525D0C4E1EA8B1BC00FF5844 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | 525D0C641EA8B22E00FF5844 /* Screen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = ""; }; 26 | 525D0C671EA8B31D00FF5844 /* MMNavigationController.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MMNavigationController.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/MMNavigationController-czhflgixahnpuugtykcifnzdczpm/Build/Products/Debug-iphonesimulator/MMNavigationController.framework"; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 525D0C3C1EA8B1BB00FF5844 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | 525D0C681EA8B31D00FF5844 /* MMNavigationController.framework in Frameworks */, 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 525D0C361EA8B1BB00FF5844 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 525D0C411EA8B1BB00FF5844 /* Example */, 45 | 525D0C401EA8B1BB00FF5844 /* Products */, 46 | 525D0C661EA8B31D00FF5844 /* Frameworks */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 525D0C401EA8B1BB00FF5844 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 525D0C3F1EA8B1BB00FF5844 /* Example.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 525D0C411EA8B1BB00FF5844 /* Example */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 525D0C421EA8B1BB00FF5844 /* AppDelegate.swift */, 62 | 525D0C441EA8B1BB00FF5844 /* ViewController.swift */, 63 | 525D0C641EA8B22E00FF5844 /* Screen.swift */, 64 | 525D0C491EA8B1BB00FF5844 /* Assets.xcassets */, 65 | 525D0C4B1EA8B1BB00FF5844 /* LaunchScreen.storyboard */, 66 | 525D0C4E1EA8B1BC00FF5844 /* Info.plist */, 67 | ); 68 | path = Example; 69 | sourceTree = ""; 70 | }; 71 | 525D0C661EA8B31D00FF5844 /* Frameworks */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 525D0C671EA8B31D00FF5844 /* MMNavigationController.framework */, 75 | ); 76 | name = Frameworks; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 525D0C3E1EA8B1BB00FF5844 /* Example */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 525D0C511EA8B1BC00FF5844 /* Build configuration list for PBXNativeTarget "Example" */; 85 | buildPhases = ( 86 | 525D0C3B1EA8B1BB00FF5844 /* Sources */, 87 | 525D0C3C1EA8B1BB00FF5844 /* Frameworks */, 88 | 525D0C3D1EA8B1BB00FF5844 /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = Example; 95 | productName = Example; 96 | productReference = 525D0C3F1EA8B1BB00FF5844 /* Example.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 525D0C371EA8B1BB00FF5844 /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | LastSwiftUpdateCheck = 0830; 106 | LastUpgradeCheck = 0900; 107 | ORGANIZATIONNAME = Aqua; 108 | TargetAttributes = { 109 | 525D0C3E1EA8B1BB00FF5844 = { 110 | CreatedOnToolsVersion = 8.3.1; 111 | DevelopmentTeam = SXRTDM2GE2; 112 | ProvisioningStyle = Automatic; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 525D0C3A1EA8B1BB00FF5844 /* Build configuration list for PBXProject "Example" */; 117 | compatibilityVersion = "Xcode 3.2"; 118 | developmentRegion = English; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 525D0C361EA8B1BB00FF5844; 125 | productRefGroup = 525D0C401EA8B1BB00FF5844 /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 525D0C3E1EA8B1BB00FF5844 /* Example */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | 525D0C3D1EA8B1BB00FF5844 /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 525D0C4D1EA8B1BB00FF5844 /* LaunchScreen.storyboard in Resources */, 140 | 525D0C4A1EA8B1BB00FF5844 /* Assets.xcassets in Resources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXResourcesBuildPhase section */ 145 | 146 | /* Begin PBXSourcesBuildPhase section */ 147 | 525D0C3B1EA8B1BB00FF5844 /* Sources */ = { 148 | isa = PBXSourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 525D0C451EA8B1BB00FF5844 /* ViewController.swift in Sources */, 152 | 525D0C431EA8B1BB00FF5844 /* AppDelegate.swift in Sources */, 153 | 525D0C651EA8B22E00FF5844 /* Screen.swift in Sources */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | /* End PBXSourcesBuildPhase section */ 158 | 159 | /* Begin PBXVariantGroup section */ 160 | 525D0C4B1EA8B1BB00FF5844 /* LaunchScreen.storyboard */ = { 161 | isa = PBXVariantGroup; 162 | children = ( 163 | 525D0C4C1EA8B1BB00FF5844 /* Base */, 164 | ); 165 | name = LaunchScreen.storyboard; 166 | sourceTree = ""; 167 | }; 168 | /* End PBXVariantGroup section */ 169 | 170 | /* Begin XCBuildConfiguration section */ 171 | 525D0C4F1EA8B1BC00FF5844 /* Debug */ = { 172 | isa = XCBuildConfiguration; 173 | buildSettings = { 174 | ALWAYS_SEARCH_USER_PATHS = NO; 175 | CLANG_ANALYZER_NONNULL = YES; 176 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 177 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 178 | CLANG_CXX_LIBRARY = "libc++"; 179 | CLANG_ENABLE_MODULES = YES; 180 | CLANG_ENABLE_OBJC_ARC = YES; 181 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 182 | CLANG_WARN_BOOL_CONVERSION = YES; 183 | CLANG_WARN_COMMA = YES; 184 | CLANG_WARN_CONSTANT_CONVERSION = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INFINITE_RECURSION = YES; 190 | CLANG_WARN_INT_CONVERSION = YES; 191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 195 | CLANG_WARN_STRICT_PROTOTYPES = YES; 196 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 200 | COPY_PHASE_STRIP = NO; 201 | DEBUG_INFORMATION_FORMAT = dwarf; 202 | ENABLE_STRICT_OBJC_MSGSEND = YES; 203 | ENABLE_TESTABILITY = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu99; 205 | GCC_DYNAMIC_NO_PIC = NO; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 219 | MTL_ENABLE_DEBUG_INFO = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = iphoneos; 222 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 223 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 224 | }; 225 | name = Debug; 226 | }; 227 | 525D0C501EA8B1BC00FF5844 /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | ALWAYS_SEARCH_USER_PATHS = NO; 231 | CLANG_ANALYZER_NONNULL = YES; 232 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_ENABLE_MODULES = YES; 236 | CLANG_ENABLE_OBJC_ARC = YES; 237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 238 | CLANG_WARN_BOOL_CONVERSION = YES; 239 | CLANG_WARN_COMMA = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = 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_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | 525D0C521EA8B1BC00FF5844 /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | DEVELOPMENT_TEAM = SXRTDM2GE2; 281 | INFOPLIST_FILE = Example/Info.plist; 282 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 283 | PRODUCT_BUNDLE_IDENTIFIER = MangoMade.Example; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | SWIFT_VERSION = 4.0; 286 | }; 287 | name = Debug; 288 | }; 289 | 525D0C531EA8B1BC00FF5844 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | DEVELOPMENT_TEAM = SXRTDM2GE2; 294 | INFOPLIST_FILE = Example/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 296 | PRODUCT_BUNDLE_IDENTIFIER = MangoMade.Example; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_VERSION = 4.0; 299 | }; 300 | name = Release; 301 | }; 302 | /* End XCBuildConfiguration section */ 303 | 304 | /* Begin XCConfigurationList section */ 305 | 525D0C3A1EA8B1BB00FF5844 /* Build configuration list for PBXProject "Example" */ = { 306 | isa = XCConfigurationList; 307 | buildConfigurations = ( 308 | 525D0C4F1EA8B1BC00FF5844 /* Debug */, 309 | 525D0C501EA8B1BC00FF5844 /* Release */, 310 | ); 311 | defaultConfigurationIsVisible = 0; 312 | defaultConfigurationName = Release; 313 | }; 314 | 525D0C511EA8B1BC00FF5844 /* Build configuration list for PBXNativeTarget "Example" */ = { 315 | isa = XCConfigurationList; 316 | buildConfigurations = ( 317 | 525D0C521EA8B1BC00FF5844 /* Debug */, 318 | 525D0C531EA8B1BC00FF5844 /* Release */, 319 | ); 320 | defaultConfigurationIsVisible = 0; 321 | defaultConfigurationName = Release; 322 | }; 323 | /* End XCConfigurationList section */ 324 | }; 325 | rootObject = 525D0C371EA8B1BB00FF5844 /* Project object */; 326 | } 327 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Aqua on 2017/4/20. 6 | // Copyright © 2017年 Aqua. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import MMNavigationController 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | UIViewController.mm.load() 19 | window = UIWindow(frame: UIScreen.main.bounds) 20 | let rootViewController = MMNavigationController(rootViewController: NormalViewController()) 21 | rootViewController.hideBottomLine() 22 | window?.rootViewController = rootViewController 23 | window?.makeKeyAndVisible() 24 | return true 25 | } 26 | 27 | func applicationWillResignActive(_ application: UIApplication) { 28 | // 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. 29 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 30 | } 31 | 32 | func applicationDidEnterBackground(_ application: UIApplication) { 33 | // 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. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | func applicationWillEnterForeground(_ application: UIApplication) { 38 | // 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. 39 | } 40 | 41 | func applicationDidBecomeActive(_ application: UIApplication) { 42 | // 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. 43 | } 44 | 45 | func applicationWillTerminate(_ application: UIApplication) { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /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 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | UIRequiredDeviceCapabilities 26 | 27 | armv7 28 | 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Example/Example/Screen.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Screen.swift 3 | // 4 | // Created by Mango on 16/7/4. 5 | // Copyright © 2016年 Homer. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | // MARK: - consts about main screen 11 | struct Screen { 12 | 13 | static var bounds: CGRect { 14 | return UIScreen.main.bounds 15 | } 16 | 17 | static var center: CGPoint { 18 | return CGPoint(x: width / 2, y: height / 2) 19 | } 20 | 21 | static var size: CGSize { 22 | return Screen.bounds.size 23 | } 24 | 25 | static var width: CGFloat { 26 | return Screen.size.width 27 | } 28 | 29 | static var height: CGFloat { 30 | return Screen.size.height 31 | } 32 | 33 | static var scale: CGFloat { 34 | return UIScreen.main.scale 35 | } 36 | 37 | static var onePX: CGFloat { 38 | return 1 / Screen.scale 39 | } 40 | 41 | static let navBarHeight: CGFloat = 64 42 | 43 | static let tabBarHeight: CGFloat = 49 44 | 45 | static var statusBarHeight: CGFloat { 46 | return UIApplication.shared.statusBarFrame.height 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MMNavigationController 4 | // 5 | // Created by Mango on 2016/11/10. 6 | // Copyright © 2016年 MangoMade. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | import MMNavigationController 12 | 13 | class BaseViewController: UIViewController { 14 | 15 | let nextButton = UIButton(type: .system) 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | view.backgroundColor = UIColor.lightGray 20 | 21 | 22 | view.addSubview(nextButton) 23 | nextButton.setTitle("To next page", for: UIControlState()) 24 | nextButton.sizeToFit() 25 | nextButton.center = Screen.center 26 | nextButton.addTarget(self, action: #selector(reponseToNext(_:)), for: .touchUpInside) 27 | 28 | } 29 | 30 | @objc func reponseToNext(_ sender: UIButton) { 31 | 32 | } 33 | 34 | } 35 | 36 | class NormalViewController: BaseViewController { 37 | 38 | override func viewDidLoad() { 39 | super.viewDidLoad() 40 | title = "Normal" 41 | } 42 | 43 | override func reponseToNext(_ sender: UIButton) { 44 | navigationController?.pushViewController(RandomColorViewController(), animated: true) 45 | } 46 | 47 | } 48 | 49 | class RandomColorViewController: BaseViewController { 50 | 51 | var delegate: TestDelegate? = TestDelegate() 52 | 53 | override func viewDidLoad() { 54 | super.viewDidLoad() 55 | view.backgroundColor = UIColor.white 56 | 57 | title = "Random Color" 58 | 59 | mm.navigationBarBackgroundColor = UIColor.random 60 | mm.popGestrueEnableWidth = 150 61 | mm.navigationBarTitleColor = UIColor.white 62 | mm.gestureDelegate = delegate 63 | 64 | let gestureEnableLabel = UILabel() 65 | gestureEnableLabel.numberOfLines = 0 66 | gestureEnableLabel.textAlignment = .center 67 | gestureEnableLabel.text = "pop手势\n\n灰色区域内\n\n有效" 68 | gestureEnableLabel.backgroundColor = UIColor.lightGray.withAlphaComponent(0.3) 69 | gestureEnableLabel.frame = CGRect(x: 0, y: 0, width: mm.popGestrueEnableWidth, height: view.bounds.height) 70 | view.addSubview(gestureEnableLabel) 71 | 72 | let scrollView = UIScrollView() 73 | scrollView.frame = CGRect(x: 0, y: 100, width: Screen.width, height: 100) 74 | scrollView.backgroundColor = .gray 75 | scrollView.contentSize = CGSize(width: Screen.width * 2, height: 100) 76 | view.addSubview(scrollView) 77 | 78 | } 79 | 80 | override func reponseToNext(_ sender: UIButton) { 81 | navigationController?.pushViewController(HiddenBarViewController(), animated: true) 82 | } 83 | 84 | } 85 | 86 | class TestDelegate: NSObject { 87 | 88 | } 89 | 90 | extension TestDelegate: UIGestureRecognizerDelegate { 91 | 92 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool { 93 | return true 94 | } 95 | } 96 | 97 | class HiddenBarViewController: BaseViewController { 98 | 99 | override func viewDidLoad() { 100 | super.viewDidLoad() 101 | mm.navigationBarHidden = true 102 | 103 | let scrollView = UIScrollView() 104 | scrollView.frame = CGRect(x: 0, y: 100, width: Screen.width, height: 100) 105 | scrollView.backgroundColor = .gray 106 | scrollView.contentSize = CGSize(width: Screen.width * 2, height: 100) 107 | view.addSubview(scrollView) 108 | } 109 | 110 | override func reponseToNext(_ sender: UIButton) { 111 | navigationController?.pushViewController(NormalViewController(), animated: true) 112 | } 113 | } 114 | 115 | extension UIColor { 116 | 117 | static var random: UIColor { 118 | let randR = CGFloat(arc4random_uniform(255)) / 255.0 119 | let randG = CGFloat(arc4random_uniform(255)) / 255.0 120 | let randB = CGFloat(arc4random_uniform(255)) / 255.0 121 | return UIColor(red: randR, green: randG, blue: randB, alpha: 1) 122 | } 123 | 124 | } 125 | 126 | extension UIImage { 127 | 128 | static func imageWithColor(_ color: UIColor) -> UIImage { 129 | let size = CGSize(width: 1, height: 1) 130 | let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) 131 | UIGraphicsBeginImageContextWithOptions(size, false, 0) 132 | color.setFill() 133 | UIRectFill(rect) 134 | let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! 135 | UIGraphicsEndImageContext() 136 | return image 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 MangoMade 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 | -------------------------------------------------------------------------------- /MMNavigationController.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint MMNavigationController.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | 12 | s.name = "MMNavigationController" 13 | s.version = "0.1.0" 14 | s.summary = "A NavigationController with fullscreen pop gesture. You can change color of navigation bar in a simple way!" 15 | 16 | s.description = <<-DESC 17 | 一句代码,即可修改导航栏颜色。 18 | 附加全屏pop手势。 19 | A NavigationController with fullscreen pop gesture. 20 | You can change color of navigation bar in a simple way! 21 | DESC 22 | 23 | s.homepage = "https://github.com/MangoMade/MMNavigationController" 24 | 25 | s.license = { :type => "MIT", :file => "LICENSE" } 26 | s.author = { "MangoMade" => "781132399@qq.com" } 27 | s.platform = :ios, "8.0" 28 | 29 | 30 | s.source = { :git => "https://github.com/MangoMade/MMNavigationController.git", :tag => "#{s.version}" } 31 | 32 | s.source_files = "Source/*.swift" 33 | 34 | s.requires_arc = true 35 | 36 | 37 | end 38 | -------------------------------------------------------------------------------- /MMNavigationController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 525D0C301EA8B06500FF5844 /* MMNavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 525D0C2E1EA8B06500FF5844 /* MMNavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 525D0C5F1EA8B22100FF5844 /* MMNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C5A1EA8B22100FF5844 /* MMNavigationController.swift */; }; 12 | 525D0C601EA8B22100FF5844 /* Namespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C5B1EA8B22100FF5844 /* Namespace.swift */; }; 13 | 525D0C611EA8B22100FF5844 /* PopGestrueDelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C5C1EA8B22100FF5844 /* PopGestrueDelegateObject.swift */; }; 14 | 525D0C621EA8B22100FF5844 /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C5D1EA8B22100FF5844 /* UIViewControllerExtension.swift */; }; 15 | 525D0C631EA8B22100FF5844 /* ViewControllerInjectBlockWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525D0C5E1EA8B22100FF5844 /* ViewControllerInjectBlockWrapper.swift */; }; 16 | 52CF142E1ED6CCFE0072A107 /* WeakReferenceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CF142D1ED6CCFE0072A107 /* WeakReferenceWrapper.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 525D0C2B1EA8B06500FF5844 /* MMNavigationController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MMNavigationController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 525D0C2E1EA8B06500FF5844 /* MMNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMNavigationController.h; sourceTree = ""; }; 22 | 525D0C2F1EA8B06500FF5844 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | 525D0C5A1EA8B22100FF5844 /* MMNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MMNavigationController.swift; sourceTree = ""; }; 24 | 525D0C5B1EA8B22100FF5844 /* Namespace.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Namespace.swift; sourceTree = ""; }; 25 | 525D0C5C1EA8B22100FF5844 /* PopGestrueDelegateObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopGestrueDelegateObject.swift; sourceTree = ""; }; 26 | 525D0C5D1EA8B22100FF5844 /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtension.swift; sourceTree = ""; }; 27 | 525D0C5E1EA8B22100FF5844 /* ViewControllerInjectBlockWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerInjectBlockWrapper.swift; sourceTree = ""; }; 28 | 52CF142D1ED6CCFE0072A107 /* WeakReferenceWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakReferenceWrapper.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 525D0C271EA8B06500FF5844 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 525D0C211EA8B06500FF5844 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 525D0C2D1EA8B06500FF5844 /* Source */, 46 | 525D0C2C1EA8B06500FF5844 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 525D0C2C1EA8B06500FF5844 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 525D0C2B1EA8B06500FF5844 /* MMNavigationController.framework */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 525D0C2D1EA8B06500FF5844 /* Source */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 525D0C2E1EA8B06500FF5844 /* MMNavigationController.h */, 62 | 525D0C5A1EA8B22100FF5844 /* MMNavigationController.swift */, 63 | 525D0C5B1EA8B22100FF5844 /* Namespace.swift */, 64 | 525D0C5C1EA8B22100FF5844 /* PopGestrueDelegateObject.swift */, 65 | 525D0C5D1EA8B22100FF5844 /* UIViewControllerExtension.swift */, 66 | 525D0C5E1EA8B22100FF5844 /* ViewControllerInjectBlockWrapper.swift */, 67 | 52CF142D1ED6CCFE0072A107 /* WeakReferenceWrapper.swift */, 68 | 525D0C2F1EA8B06500FF5844 /* Info.plist */, 69 | ); 70 | path = Source; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXHeadersBuildPhase section */ 76 | 525D0C281EA8B06500FF5844 /* Headers */ = { 77 | isa = PBXHeadersBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | 525D0C301EA8B06500FF5844 /* MMNavigationController.h in Headers */, 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXHeadersBuildPhase section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | 525D0C2A1EA8B06500FF5844 /* MMNavigationController */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = 525D0C331EA8B06500FF5844 /* Build configuration list for PBXNativeTarget "MMNavigationController" */; 90 | buildPhases = ( 91 | 525D0C261EA8B06500FF5844 /* Sources */, 92 | 525D0C271EA8B06500FF5844 /* Frameworks */, 93 | 525D0C281EA8B06500FF5844 /* Headers */, 94 | 525D0C291EA8B06500FF5844 /* Resources */, 95 | ); 96 | buildRules = ( 97 | ); 98 | dependencies = ( 99 | ); 100 | name = MMNavigationController; 101 | productName = MMNavigationController; 102 | productReference = 525D0C2B1EA8B06500FF5844 /* MMNavigationController.framework */; 103 | productType = "com.apple.product-type.framework"; 104 | }; 105 | /* End PBXNativeTarget section */ 106 | 107 | /* Begin PBXProject section */ 108 | 525D0C221EA8B06500FF5844 /* Project object */ = { 109 | isa = PBXProject; 110 | attributes = { 111 | LastUpgradeCheck = 0900; 112 | ORGANIZATIONNAME = Aqua; 113 | TargetAttributes = { 114 | 525D0C2A1EA8B06500FF5844 = { 115 | CreatedOnToolsVersion = 8.3.1; 116 | DevelopmentTeam = SXRTDM2GE2; 117 | LastSwiftMigration = 0830; 118 | ProvisioningStyle = Automatic; 119 | }; 120 | }; 121 | }; 122 | buildConfigurationList = 525D0C251EA8B06500FF5844 /* Build configuration list for PBXProject "MMNavigationController" */; 123 | compatibilityVersion = "Xcode 3.2"; 124 | developmentRegion = English; 125 | hasScannedForEncodings = 0; 126 | knownRegions = ( 127 | en, 128 | ); 129 | mainGroup = 525D0C211EA8B06500FF5844; 130 | productRefGroup = 525D0C2C1EA8B06500FF5844 /* Products */; 131 | projectDirPath = ""; 132 | projectRoot = ""; 133 | targets = ( 134 | 525D0C2A1EA8B06500FF5844 /* MMNavigationController */, 135 | ); 136 | }; 137 | /* End PBXProject section */ 138 | 139 | /* Begin PBXResourcesBuildPhase section */ 140 | 525D0C291EA8B06500FF5844 /* Resources */ = { 141 | isa = PBXResourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | 525D0C261EA8B06500FF5844 /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | 525D0C621EA8B22100FF5844 /* UIViewControllerExtension.swift in Sources */, 155 | 525D0C5F1EA8B22100FF5844 /* MMNavigationController.swift in Sources */, 156 | 525D0C611EA8B22100FF5844 /* PopGestrueDelegateObject.swift in Sources */, 157 | 52CF142E1ED6CCFE0072A107 /* WeakReferenceWrapper.swift in Sources */, 158 | 525D0C631EA8B22100FF5844 /* ViewControllerInjectBlockWrapper.swift in Sources */, 159 | 525D0C601EA8B22100FF5844 /* Namespace.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 525D0C311EA8B06500FF5844 /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 181 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 187 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 190 | CLANG_WARN_STRICT_PROTOTYPES = YES; 191 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 192 | CLANG_WARN_UNREACHABLE_CODE = YES; 193 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 194 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "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 = gnu99; 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 = 8.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 | TARGETED_DEVICE_FAMILY = "1,2"; 221 | VERSIONING_SYSTEM = "apple-generic"; 222 | VERSION_INFO_PREFIX = ""; 223 | }; 224 | name = Debug; 225 | }; 226 | 525D0C321EA8B06500FF5844 /* Release */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | ALWAYS_SEARCH_USER_PATHS = NO; 230 | CLANG_ANALYZER_NONNULL = YES; 231 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 233 | CLANG_CXX_LIBRARY = "libc++"; 234 | CLANG_ENABLE_MODULES = YES; 235 | CLANG_ENABLE_OBJC_ARC = YES; 236 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 237 | CLANG_WARN_BOOL_CONVERSION = YES; 238 | CLANG_WARN_COMMA = YES; 239 | CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 249 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 250 | CLANG_WARN_STRICT_PROTOTYPES = YES; 251 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 252 | CLANG_WARN_UNREACHABLE_CODE = YES; 253 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 254 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 255 | COPY_PHASE_STRIP = NO; 256 | CURRENT_PROJECT_VERSION = 1; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 272 | TARGETED_DEVICE_FAMILY = "1,2"; 273 | VALIDATE_PRODUCT = YES; 274 | VERSIONING_SYSTEM = "apple-generic"; 275 | VERSION_INFO_PREFIX = ""; 276 | }; 277 | name = Release; 278 | }; 279 | 525D0C341EA8B06500FF5844 /* Debug */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 283 | CLANG_ENABLE_MODULES = YES; 284 | CODE_SIGN_IDENTITY = ""; 285 | DEFINES_MODULE = YES; 286 | DEVELOPMENT_TEAM = SXRTDM2GE2; 287 | DYLIB_COMPATIBILITY_VERSION = 1; 288 | DYLIB_CURRENT_VERSION = 1; 289 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 290 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 291 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = MangoMade.MMNavigationController; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | SKIP_INSTALL = YES; 296 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 297 | SWIFT_VERSION = 4.0; 298 | }; 299 | name = Debug; 300 | }; 301 | 525D0C351EA8B06500FF5844 /* Release */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 305 | CLANG_ENABLE_MODULES = YES; 306 | CODE_SIGN_IDENTITY = ""; 307 | DEFINES_MODULE = YES; 308 | DEVELOPMENT_TEAM = SXRTDM2GE2; 309 | DYLIB_COMPATIBILITY_VERSION = 1; 310 | DYLIB_CURRENT_VERSION = 1; 311 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 312 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 313 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 314 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 315 | PRODUCT_BUNDLE_IDENTIFIER = MangoMade.MMNavigationController; 316 | PRODUCT_NAME = "$(TARGET_NAME)"; 317 | SKIP_INSTALL = YES; 318 | SWIFT_VERSION = 4.0; 319 | }; 320 | name = Release; 321 | }; 322 | /* End XCBuildConfiguration section */ 323 | 324 | /* Begin XCConfigurationList section */ 325 | 525D0C251EA8B06500FF5844 /* Build configuration list for PBXProject "MMNavigationController" */ = { 326 | isa = XCConfigurationList; 327 | buildConfigurations = ( 328 | 525D0C311EA8B06500FF5844 /* Debug */, 329 | 525D0C321EA8B06500FF5844 /* Release */, 330 | ); 331 | defaultConfigurationIsVisible = 0; 332 | defaultConfigurationName = Release; 333 | }; 334 | 525D0C331EA8B06500FF5844 /* Build configuration list for PBXNativeTarget "MMNavigationController" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | 525D0C341EA8B06500FF5844 /* Debug */, 338 | 525D0C351EA8B06500FF5844 /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | /* End XCConfigurationList section */ 344 | }; 345 | rootObject = 525D0C221EA8B06500FF5844 /* Project object */; 346 | } 347 | -------------------------------------------------------------------------------- /MMNavigationController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MMNavigationController.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Requirements 2 | 3 | * iOS 8.0 4 | * Swift 4.0 5 | * Swift 3.2请使用 0.0.5 6 | 7 | ## Cocoapods 8 | 9 | // Swift 4 10 | pod 'MMNavigationController', '~> 0.1.0’ 11 | // Swift 3.2 12 | pod 'MMNavigationController', '~> 0.0.5’ 13 | 14 | ## 解决的问题 15 | 16 | 由于`NavigationBar`的生命周期是与`UINavigationController`绑定的,所以`UINavigationController`的所有子`ViewController`都共用同一个`NavigationBar`,但是在实际开发的需求中,常常会有某个视图的导航栏颜色与其它视图的导航栏颜色不同。 17 | 18 | 修改某一个`viewController`的颜色也不难: 19 | 20 | ``` Swift 21 | override func viewWillAppear(_ animated: Bool) { 22 | super.viewWillAppear(animated) 23 | navigationController?.navigationBar.barTintColor = UIColor.blue 24 | } 25 | 26 | override func viewWillDisappear(_ animated: Bool) { 27 | super.viewWillDisappear(animated) 28 | navigationController?.navigationBar.barTintColor = UIColor.white 29 | } 30 | ``` 31 | 32 | 只是每次需要这么多代码来解决一个看似很简单的问题,非常麻烦 33 | 34 | **使用MMNavigationController后只需要一句代码,即可修改导航栏颜色:** 35 | 36 | ``` Swift 37 | mm.navigationBarBackgroundColor = UIColor.blue 38 | ``` 39 | 40 | **并且支持全屏Pop手势** 41 | 42 | 效果图: 43 | 44 | ![2016-11-12 16_52_24.gif](http://upload-images.jianshu.io/upload_images/1748971-2d8a75c1236529e1.gif?imageMogr2/auto-orient/strip) 45 | 46 | 47 | ## 使用 48 | 49 | **由于`Swift`不能重写`load`方法,所以需要在AppDelegate中调用`UIViewController.mm.load()` 50 | 然后用`MMNavigationController`代替`UINavigationController`** 51 | 52 | ``` Swift 53 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 54 | 55 | /** 高亮 **/ 56 | UIViewController.mm.load() 57 | let rootViewController = MMNavigationController(rootViewController: NormalViewController()) 58 | /** 高亮 **/ 59 | 60 | rootViewController.hideBottomLine() 61 | window = UIWindow(frame: UIScreen.main.bounds) 62 | window?.rootViewController = rootViewController 63 | window?.makeKeyAndVisible() 64 | return true 65 | } 66 | ``` 67 | 68 | 69 | 之后就可以在`ViewController`的`viewDidLoad`中设置如下属性了: 70 | 71 | ``` Swift 72 | override func viewDidLoad() { 73 | super.viewDidLoad() 74 | 75 | /// 修改当前ViewContoller的导航栏的背景颜色 76 | mm.navigationBarBackgroundColor = UIColor.random 77 | 78 | /// 修改当前ViewContoller标题颜色 79 | mm.navigationBarTitleColor = UIColor.white 80 | 81 | /// 隐藏当前ViewContoller的导航栏 82 | mm.navigationBarHidden = true 83 | 84 | 85 | /** 全屏手势相关属性 **/ 86 | 87 | /// pop 手势是否可用 88 | mm.popGestrueEnable = false 89 | 90 | /// pop 手势响应的范围 91 | mm.popGestrueEnableWidth = 150 92 | } 93 | ``` 94 | 95 | 简单易用! 96 | 97 | ## 实现 98 | 99 | 主要实现是参考了[FDFullscreenPopGesture](https://github.com/forkingdog/FDFullscreenPopGesture) 100 | 101 | 运用AOP, 在`viewWillAppear`中进行属性的设置。 102 | -------------------------------------------------------------------------------- /Source/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | 0.1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Source/MMNavigationController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MMNavigationController.h 3 | // MMNavigationController 4 | // 5 | // Created by Aqua on 2017/4/20. 6 | // Copyright © 2017年 Aqua. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for MMNavigationController. 12 | FOUNDATION_EXPORT double MMNavigationControllerVersionNumber; 13 | 14 | //! Project version string for MMNavigationController. 15 | FOUNDATION_EXPORT const unsigned char MMNavigationControllerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/MMNavigationController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | 4 | 5 | open class MMNavigationController: UINavigationController { 6 | 7 | // MARK: - properties 8 | 9 | /// navgation bar 默认背景颜色 10 | open var defaultNavigationBarBackgroundColor = UIColor.white 11 | 12 | /// navgation bar 默认标题颜色 13 | open var defaultTitleColor = UIColor.black 14 | 15 | /// full screen 手势 16 | lazy public var fullscreenInteractivePopGestureRecognizer = UIPanGestureRecognizer() 17 | 18 | /// navigation bar 主体视图,此属性用于兼容 iOS 10 19 | private lazy var barBackgoundView: UIView? = { 20 | if #available(iOS 10.0, *) { 21 | for view in self.navigationBar.subviews { 22 | if NSClassFromString("_UIBarBackground").flatMap(view.isKind(of:)) == true { 23 | return view 24 | } 25 | } 26 | } 27 | return nil 28 | }() 29 | 30 | private lazy var popGestrueDelegate: PopGestrueDelegateObject = { 31 | let delegate = PopGestrueDelegateObject() 32 | delegate.navigationController = self 33 | return delegate 34 | }() 35 | 36 | // MARK: - override 37 | override open func viewDidLoad() { 38 | super.viewDidLoad() 39 | initFullscreenGesture() 40 | 41 | /// 导航栏设置为不透明, UIViewController的view会自动向下偏移 64 42 | /// viewController.extendedLayoutIncludesOpaqueBars = true 43 | /// 以上设置可以解决这个问题 44 | navigationBar.isTranslucent = false 45 | } 46 | 47 | 48 | override open func viewWillAppear(_ animated: Bool) { 49 | super.viewWillAppear(animated) 50 | setBarBackgroundColor(defaultNavigationBarBackgroundColor, animated: false) 51 | } 52 | 53 | 54 | override open func pushViewController(_ viewController: UIViewController, animated: Bool) { 55 | 56 | let blockWrapper = ViewControllerInjectBlockWrapper { (viewController: UIViewController, animated: Bool) -> Void in 57 | 58 | viewController.navigationController? 59 | .setNavigationBarHidden(viewController.mm.navigationBarHidden, animated: animated) 60 | 61 | if let navigationController = viewController.navigationController as? MMNavigationController { 62 | 63 | let navigationBarBackgroundColor = viewController.mm.navigationBarBackgroundColor ?? navigationController.defaultNavigationBarBackgroundColor 64 | navigationController.setBarBackgroundColor(navigationBarBackgroundColor, animated: true) 65 | 66 | let titleColor = viewController.mm.navigationBarTitleColor ?? navigationController.defaultTitleColor 67 | navigationController.setTitleColor(titleColor) 68 | 69 | // 设置手势delegate 的delegate,有点绕,主要解决手势冲突问题 70 | navigationController.popGestrueDelegate.delegate = viewController.mm.gestureDelegate 71 | } 72 | let navigationBarBackgroundColor = viewController.mm.navigationBarBackgroundColor ?? self.defaultNavigationBarBackgroundColor 73 | (viewController.navigationController as? MMNavigationController)?.setBarBackgroundColor(navigationBarBackgroundColor, animated: true) 74 | 75 | } 76 | viewController.mm.viewWillAppearInjectBlock = blockWrapper 77 | viewControllers.last?.mm.viewWillAppearInjectBlock = blockWrapper 78 | super.pushViewController(viewController, animated: animated) 79 | } 80 | 81 | 82 | // MARK: - private methods 83 | 84 | private func initFullscreenGesture() { 85 | 86 | fullscreenInteractivePopGestureRecognizer.delegate = popGestrueDelegate 87 | guard let targets = interactivePopGestureRecognizer?.value(forKey: "targets") as? [AnyObject] else { return } 88 | guard let target = (targets.first as? NSObject)?.value(forKey: "target") else { return } 89 | let internalAction = NSSelectorFromString("handleNavigationTransition:") 90 | fullscreenInteractivePopGestureRecognizer.maximumNumberOfTouches = 1 91 | fullscreenInteractivePopGestureRecognizer.addTarget(target, action: internalAction) 92 | interactivePopGestureRecognizer?.isEnabled = false 93 | interactivePopGestureRecognizer?.view?.addGestureRecognizer(fullscreenInteractivePopGestureRecognizer) 94 | } 95 | 96 | // MARK: - public methods 97 | 98 | /// 设置 title 的字体颜色 99 | public func setTitleColor(_ textColor: UIColor){ 100 | if navigationBar.titleTextAttributes == nil{ 101 | navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : textColor] 102 | }else{ 103 | navigationBar.titleTextAttributes![NSAttributedStringKey.foregroundColor] = textColor 104 | } 105 | } 106 | 107 | /// 隐藏 navigation bar 底部灰线 108 | public func hideBottomLine() { 109 | navigationBar.shadowImage = UIImage() 110 | navigationBar.setBackgroundImage(UIImage(), for: .default) 111 | } 112 | 113 | /// 设置返回按钮图片 114 | public func setBackButtonImage(_ image: UIImage){ 115 | let backButtonImage = image.withRenderingMode(.alwaysOriginal) 116 | navigationBar.backIndicatorImage = backButtonImage 117 | navigationBar.backIndicatorTransitionMaskImage = backButtonImage 118 | } 119 | 120 | /// 设置 navigation bar 背景颜色 121 | public func setBarBackgroundColor(_ color: UIColor, animated: Bool) { 122 | let duration = animated ? 0.25 : 0.0 123 | UIView.animate(withDuration: duration, animations: { 124 | self.navigationBar.barTintColor = color 125 | self.barBackgoundView?.backgroundColor = color 126 | }) 127 | } 128 | } 129 | 130 | 131 | -------------------------------------------------------------------------------- /Source/Namespace.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Namespace.swift 3 | // StaticCellKit 4 | // 5 | // Created by Mango on 2017/4/5. 6 | // Copyright © 2017年 MangoMade. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol NamespaceWrappable: class { 12 | 13 | associatedtype WrapperType 14 | 15 | var mm: WrapperType { get set } 16 | 17 | static var mm: WrapperType.Type { get } 18 | } 19 | 20 | public extension NamespaceWrappable { 21 | 22 | var mm: TypeWrapper { 23 | get { 24 | return TypeWrapper(self) 25 | } 26 | set { } 27 | } 28 | 29 | static var mm: TypeWrapper.Type { 30 | return TypeWrapper.self 31 | } 32 | } 33 | 34 | public protocol TypeWrapperProtocol { 35 | 36 | associatedtype WrapperObject 37 | 38 | var wrapperObject: WrapperObject { get } 39 | 40 | init(_ wrapperObject: WrapperObject) 41 | 42 | } 43 | 44 | public struct TypeWrapper: TypeWrapperProtocol { 45 | 46 | public let wrapperObject: T 47 | 48 | public init(_ wrapperObject: T) { 49 | self.wrapperObject = wrapperObject 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /Source/PopGestrueDelegateObject.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PopGestrueDelegateObject.swift 3 | // MMNavigationController 4 | // 5 | // Created by Mango on 2017/4/9. 6 | // Copyright © 2017年 MangoMade. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // MARK: - NavigationControllerPopGestrueDelegate 12 | internal class PopGestrueDelegateObject: NSObject { 13 | 14 | weak var navigationController: UINavigationController? 15 | 16 | weak var delegate: UIGestureRecognizerDelegate? 17 | } 18 | 19 | // MARK: - UIGestureRecognizerDelegate 20 | extension PopGestrueDelegateObject: UIGestureRecognizerDelegate { 21 | 22 | 23 | /// 这里主要参考了 FDFullscreenPopGesture 24 | @objc func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 25 | 26 | guard let navigationController = navigationController, 27 | let gestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { 28 | return false 29 | } 30 | 31 | if navigationController.viewControllers.count <= 1 { 32 | return false 33 | } 34 | 35 | let topViewController = navigationController.viewControllers.last 36 | if topViewController?.mm.popGestrueEnable == false { 37 | return false 38 | } 39 | 40 | let startLocation = gestureRecognizer.location(in: gestureRecognizer.view) 41 | let enableWidth = topViewController?.mm.popGestrueEnableWidth ?? 0 42 | if enableWidth > 0 && startLocation.x > enableWidth { 43 | return false 44 | } 45 | 46 | if navigationController.value(forKey: "_isTransitioning") as? Bool == true { 47 | return false 48 | } 49 | 50 | let translation = gestureRecognizer.translation(in: gestureRecognizer.view) 51 | if translation.x <= 0 { 52 | return false 53 | } 54 | 55 | return delegate?.gestureRecognizerShouldBegin?(gestureRecognizer) ?? true 56 | } 57 | 58 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool { 59 | return delegate?.gestureRecognizer?(gestureRecognizer, shouldBeRequiredToFailBy:otherGestureRecognizer) ?? false 60 | } 61 | 62 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool { 63 | return delegate?.gestureRecognizer?(gestureRecognizer, shouldRequireFailureOf: otherGestureRecognizer) ?? false 64 | } 65 | 66 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 67 | return delegate?.gestureRecognizer?(gestureRecognizer ,shouldRecognizeSimultaneouslyWith: otherGestureRecognizer) ?? false 68 | } 69 | 70 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { 71 | return delegate?.gestureRecognizer?(gestureRecognizer ,shouldReceive: touch) ?? true 72 | } 73 | 74 | @available(iOS 9.0, *) 75 | func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive press: UIPress) -> Bool { 76 | return delegate?.gestureRecognizer?(gestureRecognizer ,shouldReceive: press) ?? true 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/UIViewControllerExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewControllerExtension.swift 3 | // MMNavigationController 4 | // 5 | // Created by Mango on 2017/4/9. 6 | // Copyright © 2017年 MangoMade. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIViewController: NamespaceWrappable { } 12 | 13 | private extension TypeWrapper { 14 | var viewController: T { 15 | return wrapperObject 16 | } 17 | } 18 | 19 | fileprivate struct AssociatedKey { 20 | static var viewWillAppearInjectBlock = 0 21 | static var navigationBarHidden = 0 22 | static var popGestrueEnable = 0 23 | static var navigationBarBackgroundColor = 0 24 | static var popGestrueEnableWidth = 0 25 | static var navigationBarTitleColor = 0 26 | static var gestureDelegate = 0 27 | } 28 | 29 | public extension TypeWrapper where T: UIViewController { 30 | 31 | /// 在AppDelegate中调用此方法 32 | public static func load() { 33 | UIViewController.methodsSwizzling 34 | } 35 | 36 | /// navigationBar 是否隐藏 37 | public var navigationBarHidden: Bool { 38 | get { 39 | var hidden = objc_getAssociatedObject(self.viewController, &AssociatedKey.navigationBarHidden) as? NSNumber 40 | if hidden == nil { 41 | hidden = NSNumber(booleanLiteral: false) 42 | objc_setAssociatedObject(self.viewController, 43 | &AssociatedKey.navigationBarHidden, 44 | hidden, 45 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 46 | } 47 | return hidden!.boolValue 48 | } 49 | set { 50 | objc_setAssociatedObject(self.viewController, 51 | &AssociatedKey.navigationBarHidden, 52 | NSNumber(booleanLiteral: newValue), 53 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 54 | } 55 | } 56 | 57 | /// pop 手势是否可用 58 | public var popGestrueEnable: Bool { 59 | get { 60 | var enable = objc_getAssociatedObject(self.viewController, &AssociatedKey.popGestrueEnable) as? NSNumber 61 | if enable == nil { 62 | enable = NSNumber(booleanLiteral: true) 63 | objc_setAssociatedObject(self.viewController, 64 | &AssociatedKey.popGestrueEnable, 65 | enable, 66 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 67 | } 68 | return enable!.boolValue 69 | } 70 | set { 71 | objc_setAssociatedObject(self.viewController, 72 | &AssociatedKey.popGestrueEnable, 73 | NSNumber(booleanLiteral: newValue), 74 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 75 | } 76 | } 77 | 78 | /// pop手势可用宽度,从左开始计算 79 | public var popGestrueEnableWidth: CGFloat { 80 | get { 81 | var width = objc_getAssociatedObject(self.viewController, &AssociatedKey.popGestrueEnableWidth) as? NSNumber 82 | if width == nil { 83 | width = NSNumber(floatLiteral: 0) 84 | objc_setAssociatedObject(self.viewController, 85 | &AssociatedKey.popGestrueEnableWidth, 86 | width, 87 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 88 | } 89 | return CGFloat(width!.floatValue) 90 | } 91 | set { 92 | objc_setAssociatedObject(self.viewController, 93 | &AssociatedKey.popGestrueEnableWidth, 94 | NSNumber(floatLiteral: Double(newValue)), 95 | .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 96 | } 97 | } 98 | 99 | /// navigationBar 背景颜色 100 | public var navigationBarBackgroundColor: UIColor? { 101 | get { 102 | return objc_getAssociatedObject(self.viewController, &AssociatedKey.navigationBarBackgroundColor) as? UIColor 103 | } 104 | set { 105 | objc_setAssociatedObject(self.viewController, &AssociatedKey.navigationBarBackgroundColor, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 106 | } 107 | } 108 | 109 | /// navigationBar 标题字体颜色 110 | public var navigationBarTitleColor: UIColor? { 111 | get { 112 | return objc_getAssociatedObject(self.viewController, &AssociatedKey.navigationBarTitleColor) as? UIColor 113 | } 114 | set { 115 | objc_setAssociatedObject(self.viewController, &AssociatedKey.navigationBarTitleColor, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 116 | } 117 | } 118 | 119 | /// gesture delegate 120 | /// 可以通过设置这个代理,实现代理方法,解决手势冲突等问题 121 | public weak var gestureDelegate: UIGestureRecognizerDelegate? { 122 | get { 123 | return gestureDelegateWrapper.instance 124 | } 125 | set { 126 | gestureDelegateWrapper.instance = newValue 127 | } 128 | } 129 | 130 | private var gestureDelegateWrapper: WeakReferenceWrapper { 131 | var wrapper = objc_getAssociatedObject(self.viewController, &AssociatedKey.gestureDelegate) as? WeakReferenceWrapper 132 | if wrapper == nil { 133 | wrapper = WeakReferenceWrapper() 134 | objc_setAssociatedObject(self.viewController, &AssociatedKey.gestureDelegate, wrapper, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 135 | } 136 | return wrapper! 137 | } 138 | 139 | internal var viewWillAppearInjectBlock: ViewControllerInjectBlockWrapper? { 140 | get { 141 | return objc_getAssociatedObject(self.viewController, &AssociatedKey.viewWillAppearInjectBlock) as? ViewControllerInjectBlockWrapper 142 | } 143 | set { 144 | objc_setAssociatedObject(self.viewController, &AssociatedKey.viewWillAppearInjectBlock, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) 145 | } 146 | } 147 | } 148 | 149 | extension UIViewController { 150 | 151 | fileprivate static let methodsSwizzling: () = { 152 | guard let originalViewWillAppearSelector = class_getInstanceMethod(UIViewController.self, #selector(viewWillAppear(_:))), 153 | let swizzledViewWillAppearSelector = class_getInstanceMethod(UIViewController.self, #selector(mm_viewWillAppear(_:))) else { 154 | return 155 | } 156 | method_exchangeImplementations(originalViewWillAppearSelector, swizzledViewWillAppearSelector) 157 | }() 158 | 159 | // MARK - private methods 160 | @objc fileprivate func mm_viewWillAppear(_ animated: Bool) { 161 | mm_viewWillAppear(animated) 162 | mm.viewWillAppearInjectBlock?.block?(self, animated) 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /Source/ViewControllerInjectBlockWrapper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewControllerInjectBlockWrapper.swift 3 | // MMNavigationController 4 | // 5 | // Created by Mango on 2017/4/9. 6 | // Copyright © 2017年 MangoMade. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewControllerInjectBlockWrapper { 12 | 13 | var block: ((_ viewController: UIViewController, _ animated: Bool) -> Void)? 14 | 15 | init(block: ((_ viewController: UIViewController, _ animated: Bool) -> Void)?) { 16 | self.block = block 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/WeakReferenceWrapper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WeakReferenceWrapper.swift 3 | // StaticCellKit 4 | // 5 | // Created by Mango on 2017/4/5. 6 | // Copyright © 2017年 MangoMade. All rights reserved. 7 | // 8 | 9 | 10 | 11 | internal class WeakReferenceWrapper { 12 | 13 | weak var instance: WrappedType? 14 | 15 | } 16 | --------------------------------------------------------------------------------