├── .gitignore ├── README.md ├── SwitchViewController.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SwitchViewController ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ContainerViewController.h ├── ContainerViewController.m ├── FirstViewController.h ├── FirstViewController.m ├── Info.plist ├── SecondViewController.h ├── SecondViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── SwitchViewControllerTests ├── Info.plist └── SwitchViewControllerTests.m └── SwitchViewControllerUITests ├── Info.plist └── SwitchViewControllerUITests.m /.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 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwitchViewController 2 | The correct way to add child controllers 3 | 4 | ### Demo对应的博客地址:[如何正确添加Child View Controller](http://imliaoyuan.com/2016/08/30/%E5%A6%82%E4%BD%95%E6%AD%A3%E7%A1%AE%E6%B7%BB%E5%8A%A0child_view_controller/) 5 | -------------------------------------------------------------------------------- /SwitchViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DBC575C31D75907E00973FD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575C21D75907E00973FD2 /* main.m */; }; 11 | DBC575C61D75907E00973FD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575C51D75907E00973FD2 /* AppDelegate.m */; }; 12 | DBC575C91D75907F00973FD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575C81D75907F00973FD2 /* ViewController.m */; }; 13 | DBC575CC1D75907F00973FD2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBC575CA1D75907F00973FD2 /* Main.storyboard */; }; 14 | DBC575CE1D75907F00973FD2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DBC575CD1D75907F00973FD2 /* Assets.xcassets */; }; 15 | DBC575D11D75907F00973FD2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBC575CF1D75907F00973FD2 /* LaunchScreen.storyboard */; }; 16 | DBC575DC1D75907F00973FD2 /* SwitchViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575DB1D75907F00973FD2 /* SwitchViewControllerTests.m */; }; 17 | DBC575E71D75907F00973FD2 /* SwitchViewControllerUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575E61D75907F00973FD2 /* SwitchViewControllerUITests.m */; }; 18 | DBC575FA1D7590A700973FD2 /* ContainerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575F51D7590A700973FD2 /* ContainerViewController.m */; }; 19 | DBC575FB1D7590A700973FD2 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575F71D7590A700973FD2 /* FirstViewController.m */; }; 20 | DBC575FC1D7590A700973FD2 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBC575F91D7590A700973FD2 /* SecondViewController.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | DBC575D81D75907F00973FD2 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = DBC575B61D75907E00973FD2 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = DBC575BD1D75907E00973FD2; 29 | remoteInfo = SwitchViewController; 30 | }; 31 | DBC575E31D75907F00973FD2 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = DBC575B61D75907E00973FD2 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = DBC575BD1D75907E00973FD2; 36 | remoteInfo = SwitchViewController; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | DBC575BE1D75907E00973FD2 /* SwitchViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwitchViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | DBC575C21D75907E00973FD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 43 | DBC575C41D75907E00973FD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | DBC575C51D75907E00973FD2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | DBC575C71D75907E00973FD2 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | DBC575C81D75907F00973FD2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | DBC575CB1D75907F00973FD2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | DBC575CD1D75907F00973FD2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | DBC575D01D75907F00973FD2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | DBC575D21D75907F00973FD2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | DBC575D71D75907F00973FD2 /* SwitchViewControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwitchViewControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | DBC575DB1D75907F00973FD2 /* SwitchViewControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SwitchViewControllerTests.m; sourceTree = ""; }; 53 | DBC575DD1D75907F00973FD2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | DBC575E21D75907F00973FD2 /* SwitchViewControllerUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwitchViewControllerUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | DBC575E61D75907F00973FD2 /* SwitchViewControllerUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SwitchViewControllerUITests.m; sourceTree = ""; }; 56 | DBC575E81D75907F00973FD2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | DBC575F41D7590A700973FD2 /* ContainerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContainerViewController.h; sourceTree = ""; }; 58 | DBC575F51D7590A700973FD2 /* ContainerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContainerViewController.m; sourceTree = ""; }; 59 | DBC575F61D7590A700973FD2 /* FirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; }; 60 | DBC575F71D7590A700973FD2 /* FirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; }; 61 | DBC575F81D7590A700973FD2 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 62 | DBC575F91D7590A700973FD2 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 63 | /* End PBXFileReference section */ 64 | 65 | /* Begin PBXFrameworksBuildPhase section */ 66 | DBC575BB1D75907E00973FD2 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | DBC575D41D75907F00973FD2 /* Frameworks */ = { 74 | isa = PBXFrameworksBuildPhase; 75 | buildActionMask = 2147483647; 76 | files = ( 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | DBC575DF1D75907F00973FD2 /* Frameworks */ = { 81 | isa = PBXFrameworksBuildPhase; 82 | buildActionMask = 2147483647; 83 | files = ( 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | /* End PBXFrameworksBuildPhase section */ 88 | 89 | /* Begin PBXGroup section */ 90 | DBC575B51D75907E00973FD2 = { 91 | isa = PBXGroup; 92 | children = ( 93 | DBC575C01D75907E00973FD2 /* SwitchViewController */, 94 | DBC575DA1D75907F00973FD2 /* SwitchViewControllerTests */, 95 | DBC575E51D75907F00973FD2 /* SwitchViewControllerUITests */, 96 | DBC575BF1D75907E00973FD2 /* Products */, 97 | ); 98 | sourceTree = ""; 99 | }; 100 | DBC575BF1D75907E00973FD2 /* Products */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | DBC575BE1D75907E00973FD2 /* SwitchViewController.app */, 104 | DBC575D71D75907F00973FD2 /* SwitchViewControllerTests.xctest */, 105 | DBC575E21D75907F00973FD2 /* SwitchViewControllerUITests.xctest */, 106 | ); 107 | name = Products; 108 | sourceTree = ""; 109 | }; 110 | DBC575C01D75907E00973FD2 /* SwitchViewController */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | DBC575C41D75907E00973FD2 /* AppDelegate.h */, 114 | DBC575C51D75907E00973FD2 /* AppDelegate.m */, 115 | DBC575C71D75907E00973FD2 /* ViewController.h */, 116 | DBC575C81D75907F00973FD2 /* ViewController.m */, 117 | DBC575F41D7590A700973FD2 /* ContainerViewController.h */, 118 | DBC575F51D7590A700973FD2 /* ContainerViewController.m */, 119 | DBC575F61D7590A700973FD2 /* FirstViewController.h */, 120 | DBC575F71D7590A700973FD2 /* FirstViewController.m */, 121 | DBC575F81D7590A700973FD2 /* SecondViewController.h */, 122 | DBC575F91D7590A700973FD2 /* SecondViewController.m */, 123 | DBC575CA1D75907F00973FD2 /* Main.storyboard */, 124 | DBC575CD1D75907F00973FD2 /* Assets.xcassets */, 125 | DBC575CF1D75907F00973FD2 /* LaunchScreen.storyboard */, 126 | DBC575D21D75907F00973FD2 /* Info.plist */, 127 | DBC575C11D75907E00973FD2 /* Supporting Files */, 128 | ); 129 | path = SwitchViewController; 130 | sourceTree = ""; 131 | }; 132 | DBC575C11D75907E00973FD2 /* Supporting Files */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | DBC575C21D75907E00973FD2 /* main.m */, 136 | ); 137 | name = "Supporting Files"; 138 | sourceTree = ""; 139 | }; 140 | DBC575DA1D75907F00973FD2 /* SwitchViewControllerTests */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | DBC575DB1D75907F00973FD2 /* SwitchViewControllerTests.m */, 144 | DBC575DD1D75907F00973FD2 /* Info.plist */, 145 | ); 146 | path = SwitchViewControllerTests; 147 | sourceTree = ""; 148 | }; 149 | DBC575E51D75907F00973FD2 /* SwitchViewControllerUITests */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | DBC575E61D75907F00973FD2 /* SwitchViewControllerUITests.m */, 153 | DBC575E81D75907F00973FD2 /* Info.plist */, 154 | ); 155 | path = SwitchViewControllerUITests; 156 | sourceTree = ""; 157 | }; 158 | /* End PBXGroup section */ 159 | 160 | /* Begin PBXNativeTarget section */ 161 | DBC575BD1D75907E00973FD2 /* SwitchViewController */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = DBC575EB1D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewController" */; 164 | buildPhases = ( 165 | DBC575BA1D75907E00973FD2 /* Sources */, 166 | DBC575BB1D75907E00973FD2 /* Frameworks */, 167 | DBC575BC1D75907E00973FD2 /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | ); 173 | name = SwitchViewController; 174 | productName = SwitchViewController; 175 | productReference = DBC575BE1D75907E00973FD2 /* SwitchViewController.app */; 176 | productType = "com.apple.product-type.application"; 177 | }; 178 | DBC575D61D75907F00973FD2 /* SwitchViewControllerTests */ = { 179 | isa = PBXNativeTarget; 180 | buildConfigurationList = DBC575EE1D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewControllerTests" */; 181 | buildPhases = ( 182 | DBC575D31D75907F00973FD2 /* Sources */, 183 | DBC575D41D75907F00973FD2 /* Frameworks */, 184 | DBC575D51D75907F00973FD2 /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | DBC575D91D75907F00973FD2 /* PBXTargetDependency */, 190 | ); 191 | name = SwitchViewControllerTests; 192 | productName = SwitchViewControllerTests; 193 | productReference = DBC575D71D75907F00973FD2 /* SwitchViewControllerTests.xctest */; 194 | productType = "com.apple.product-type.bundle.unit-test"; 195 | }; 196 | DBC575E11D75907F00973FD2 /* SwitchViewControllerUITests */ = { 197 | isa = PBXNativeTarget; 198 | buildConfigurationList = DBC575F11D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewControllerUITests" */; 199 | buildPhases = ( 200 | DBC575DE1D75907F00973FD2 /* Sources */, 201 | DBC575DF1D75907F00973FD2 /* Frameworks */, 202 | DBC575E01D75907F00973FD2 /* Resources */, 203 | ); 204 | buildRules = ( 205 | ); 206 | dependencies = ( 207 | DBC575E41D75907F00973FD2 /* PBXTargetDependency */, 208 | ); 209 | name = SwitchViewControllerUITests; 210 | productName = SwitchViewControllerUITests; 211 | productReference = DBC575E21D75907F00973FD2 /* SwitchViewControllerUITests.xctest */; 212 | productType = "com.apple.product-type.bundle.ui-testing"; 213 | }; 214 | /* End PBXNativeTarget section */ 215 | 216 | /* Begin PBXProject section */ 217 | DBC575B61D75907E00973FD2 /* Project object */ = { 218 | isa = PBXProject; 219 | attributes = { 220 | LastUpgradeCheck = 0730; 221 | ORGANIZATIONNAME = Spark; 222 | TargetAttributes = { 223 | DBC575BD1D75907E00973FD2 = { 224 | CreatedOnToolsVersion = 7.3.1; 225 | }; 226 | DBC575D61D75907F00973FD2 = { 227 | CreatedOnToolsVersion = 7.3.1; 228 | TestTargetID = DBC575BD1D75907E00973FD2; 229 | }; 230 | DBC575E11D75907F00973FD2 = { 231 | CreatedOnToolsVersion = 7.3.1; 232 | TestTargetID = DBC575BD1D75907E00973FD2; 233 | }; 234 | }; 235 | }; 236 | buildConfigurationList = DBC575B91D75907E00973FD2 /* Build configuration list for PBXProject "SwitchViewController" */; 237 | compatibilityVersion = "Xcode 3.2"; 238 | developmentRegion = English; 239 | hasScannedForEncodings = 0; 240 | knownRegions = ( 241 | en, 242 | Base, 243 | ); 244 | mainGroup = DBC575B51D75907E00973FD2; 245 | productRefGroup = DBC575BF1D75907E00973FD2 /* Products */; 246 | projectDirPath = ""; 247 | projectRoot = ""; 248 | targets = ( 249 | DBC575BD1D75907E00973FD2 /* SwitchViewController */, 250 | DBC575D61D75907F00973FD2 /* SwitchViewControllerTests */, 251 | DBC575E11D75907F00973FD2 /* SwitchViewControllerUITests */, 252 | ); 253 | }; 254 | /* End PBXProject section */ 255 | 256 | /* Begin PBXResourcesBuildPhase section */ 257 | DBC575BC1D75907E00973FD2 /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | DBC575D11D75907F00973FD2 /* LaunchScreen.storyboard in Resources */, 262 | DBC575CE1D75907F00973FD2 /* Assets.xcassets in Resources */, 263 | DBC575CC1D75907F00973FD2 /* Main.storyboard in Resources */, 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | DBC575D51D75907F00973FD2 /* Resources */ = { 268 | isa = PBXResourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | DBC575E01D75907F00973FD2 /* Resources */ = { 275 | isa = PBXResourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXResourcesBuildPhase section */ 282 | 283 | /* Begin PBXSourcesBuildPhase section */ 284 | DBC575BA1D75907E00973FD2 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | DBC575FC1D7590A700973FD2 /* SecondViewController.m in Sources */, 289 | DBC575C91D75907F00973FD2 /* ViewController.m in Sources */, 290 | DBC575C61D75907E00973FD2 /* AppDelegate.m in Sources */, 291 | DBC575FB1D7590A700973FD2 /* FirstViewController.m in Sources */, 292 | DBC575FA1D7590A700973FD2 /* ContainerViewController.m in Sources */, 293 | DBC575C31D75907E00973FD2 /* main.m in Sources */, 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | DBC575D31D75907F00973FD2 /* Sources */ = { 298 | isa = PBXSourcesBuildPhase; 299 | buildActionMask = 2147483647; 300 | files = ( 301 | DBC575DC1D75907F00973FD2 /* SwitchViewControllerTests.m in Sources */, 302 | ); 303 | runOnlyForDeploymentPostprocessing = 0; 304 | }; 305 | DBC575DE1D75907F00973FD2 /* Sources */ = { 306 | isa = PBXSourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | DBC575E71D75907F00973FD2 /* SwitchViewControllerUITests.m in Sources */, 310 | ); 311 | runOnlyForDeploymentPostprocessing = 0; 312 | }; 313 | /* End PBXSourcesBuildPhase section */ 314 | 315 | /* Begin PBXTargetDependency section */ 316 | DBC575D91D75907F00973FD2 /* PBXTargetDependency */ = { 317 | isa = PBXTargetDependency; 318 | target = DBC575BD1D75907E00973FD2 /* SwitchViewController */; 319 | targetProxy = DBC575D81D75907F00973FD2 /* PBXContainerItemProxy */; 320 | }; 321 | DBC575E41D75907F00973FD2 /* PBXTargetDependency */ = { 322 | isa = PBXTargetDependency; 323 | target = DBC575BD1D75907E00973FD2 /* SwitchViewController */; 324 | targetProxy = DBC575E31D75907F00973FD2 /* PBXContainerItemProxy */; 325 | }; 326 | /* End PBXTargetDependency section */ 327 | 328 | /* Begin PBXVariantGroup section */ 329 | DBC575CA1D75907F00973FD2 /* Main.storyboard */ = { 330 | isa = PBXVariantGroup; 331 | children = ( 332 | DBC575CB1D75907F00973FD2 /* Base */, 333 | ); 334 | name = Main.storyboard; 335 | sourceTree = ""; 336 | }; 337 | DBC575CF1D75907F00973FD2 /* LaunchScreen.storyboard */ = { 338 | isa = PBXVariantGroup; 339 | children = ( 340 | DBC575D01D75907F00973FD2 /* Base */, 341 | ); 342 | name = LaunchScreen.storyboard; 343 | sourceTree = ""; 344 | }; 345 | /* End PBXVariantGroup section */ 346 | 347 | /* Begin XCBuildConfiguration section */ 348 | DBC575E91D75907F00973FD2 /* Debug */ = { 349 | isa = XCBuildConfiguration; 350 | buildSettings = { 351 | ALWAYS_SEARCH_USER_PATHS = NO; 352 | CLANG_ANALYZER_NONNULL = YES; 353 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 354 | CLANG_CXX_LIBRARY = "libc++"; 355 | CLANG_ENABLE_MODULES = YES; 356 | CLANG_ENABLE_OBJC_ARC = YES; 357 | CLANG_WARN_BOOL_CONVERSION = YES; 358 | CLANG_WARN_CONSTANT_CONVERSION = YES; 359 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 360 | CLANG_WARN_EMPTY_BODY = YES; 361 | CLANG_WARN_ENUM_CONVERSION = YES; 362 | CLANG_WARN_INT_CONVERSION = YES; 363 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 364 | CLANG_WARN_UNREACHABLE_CODE = YES; 365 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 366 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 367 | COPY_PHASE_STRIP = NO; 368 | DEBUG_INFORMATION_FORMAT = dwarf; 369 | ENABLE_STRICT_OBJC_MSGSEND = YES; 370 | ENABLE_TESTABILITY = YES; 371 | GCC_C_LANGUAGE_STANDARD = gnu99; 372 | GCC_DYNAMIC_NO_PIC = NO; 373 | GCC_NO_COMMON_BLOCKS = YES; 374 | GCC_OPTIMIZATION_LEVEL = 0; 375 | GCC_PREPROCESSOR_DEFINITIONS = ( 376 | "DEBUG=1", 377 | "$(inherited)", 378 | ); 379 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 380 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 381 | GCC_WARN_UNDECLARED_SELECTOR = YES; 382 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 383 | GCC_WARN_UNUSED_FUNCTION = YES; 384 | GCC_WARN_UNUSED_VARIABLE = YES; 385 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 386 | MTL_ENABLE_DEBUG_INFO = YES; 387 | ONLY_ACTIVE_ARCH = YES; 388 | SDKROOT = iphoneos; 389 | TARGETED_DEVICE_FAMILY = "1,2"; 390 | }; 391 | name = Debug; 392 | }; 393 | DBC575EA1D75907F00973FD2 /* Release */ = { 394 | isa = XCBuildConfiguration; 395 | buildSettings = { 396 | ALWAYS_SEARCH_USER_PATHS = NO; 397 | CLANG_ANALYZER_NONNULL = YES; 398 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 399 | CLANG_CXX_LIBRARY = "libc++"; 400 | CLANG_ENABLE_MODULES = YES; 401 | CLANG_ENABLE_OBJC_ARC = YES; 402 | CLANG_WARN_BOOL_CONVERSION = YES; 403 | CLANG_WARN_CONSTANT_CONVERSION = YES; 404 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 405 | CLANG_WARN_EMPTY_BODY = YES; 406 | CLANG_WARN_ENUM_CONVERSION = YES; 407 | CLANG_WARN_INT_CONVERSION = YES; 408 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 409 | CLANG_WARN_UNREACHABLE_CODE = YES; 410 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 411 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 412 | COPY_PHASE_STRIP = NO; 413 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 414 | ENABLE_NS_ASSERTIONS = NO; 415 | ENABLE_STRICT_OBJC_MSGSEND = YES; 416 | GCC_C_LANGUAGE_STANDARD = gnu99; 417 | GCC_NO_COMMON_BLOCKS = YES; 418 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 419 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 420 | GCC_WARN_UNDECLARED_SELECTOR = YES; 421 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 422 | GCC_WARN_UNUSED_FUNCTION = YES; 423 | GCC_WARN_UNUSED_VARIABLE = YES; 424 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 425 | MTL_ENABLE_DEBUG_INFO = NO; 426 | SDKROOT = iphoneos; 427 | TARGETED_DEVICE_FAMILY = "1,2"; 428 | VALIDATE_PRODUCT = YES; 429 | }; 430 | name = Release; 431 | }; 432 | DBC575EC1D75907F00973FD2 /* Debug */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 436 | INFOPLIST_FILE = SwitchViewController/Info.plist; 437 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 438 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewController; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | }; 441 | name = Debug; 442 | }; 443 | DBC575ED1D75907F00973FD2 /* Release */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 447 | INFOPLIST_FILE = SwitchViewController/Info.plist; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewController; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | }; 452 | name = Release; 453 | }; 454 | DBC575EF1D75907F00973FD2 /* Debug */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | BUNDLE_LOADER = "$(TEST_HOST)"; 458 | INFOPLIST_FILE = SwitchViewControllerTests/Info.plist; 459 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 460 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewControllerTests; 461 | PRODUCT_NAME = "$(TARGET_NAME)"; 462 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwitchViewController.app/SwitchViewController"; 463 | }; 464 | name = Debug; 465 | }; 466 | DBC575F01D75907F00973FD2 /* Release */ = { 467 | isa = XCBuildConfiguration; 468 | buildSettings = { 469 | BUNDLE_LOADER = "$(TEST_HOST)"; 470 | INFOPLIST_FILE = SwitchViewControllerTests/Info.plist; 471 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 472 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewControllerTests; 473 | PRODUCT_NAME = "$(TARGET_NAME)"; 474 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwitchViewController.app/SwitchViewController"; 475 | }; 476 | name = Release; 477 | }; 478 | DBC575F21D75907F00973FD2 /* Debug */ = { 479 | isa = XCBuildConfiguration; 480 | buildSettings = { 481 | INFOPLIST_FILE = SwitchViewControllerUITests/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 483 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewControllerUITests; 484 | PRODUCT_NAME = "$(TARGET_NAME)"; 485 | TEST_TARGET_NAME = SwitchViewController; 486 | }; 487 | name = Debug; 488 | }; 489 | DBC575F31D75907F00973FD2 /* Release */ = { 490 | isa = XCBuildConfiguration; 491 | buildSettings = { 492 | INFOPLIST_FILE = SwitchViewControllerUITests/Info.plist; 493 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 494 | PRODUCT_BUNDLE_IDENTIFIER = com.imliaoyuan.www.SwitchViewControllerUITests; 495 | PRODUCT_NAME = "$(TARGET_NAME)"; 496 | TEST_TARGET_NAME = SwitchViewController; 497 | }; 498 | name = Release; 499 | }; 500 | /* End XCBuildConfiguration section */ 501 | 502 | /* Begin XCConfigurationList section */ 503 | DBC575B91D75907E00973FD2 /* Build configuration list for PBXProject "SwitchViewController" */ = { 504 | isa = XCConfigurationList; 505 | buildConfigurations = ( 506 | DBC575E91D75907F00973FD2 /* Debug */, 507 | DBC575EA1D75907F00973FD2 /* Release */, 508 | ); 509 | defaultConfigurationIsVisible = 0; 510 | defaultConfigurationName = Release; 511 | }; 512 | DBC575EB1D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewController" */ = { 513 | isa = XCConfigurationList; 514 | buildConfigurations = ( 515 | DBC575EC1D75907F00973FD2 /* Debug */, 516 | DBC575ED1D75907F00973FD2 /* Release */, 517 | ); 518 | defaultConfigurationIsVisible = 0; 519 | }; 520 | DBC575EE1D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewControllerTests" */ = { 521 | isa = XCConfigurationList; 522 | buildConfigurations = ( 523 | DBC575EF1D75907F00973FD2 /* Debug */, 524 | DBC575F01D75907F00973FD2 /* Release */, 525 | ); 526 | defaultConfigurationIsVisible = 0; 527 | }; 528 | DBC575F11D75907F00973FD2 /* Build configuration list for PBXNativeTarget "SwitchViewControllerUITests" */ = { 529 | isa = XCConfigurationList; 530 | buildConfigurations = ( 531 | DBC575F21D75907F00973FD2 /* Debug */, 532 | DBC575F31D75907F00973FD2 /* Release */, 533 | ); 534 | defaultConfigurationIsVisible = 0; 535 | }; 536 | /* End XCConfigurationList section */ 537 | }; 538 | rootObject = DBC575B61D75907E00973FD2 /* Project object */; 539 | } 540 | -------------------------------------------------------------------------------- /SwitchViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwitchViewController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /SwitchViewController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /SwitchViewController/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SwitchViewController/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 | -------------------------------------------------------------------------------- /SwitchViewController/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /SwitchViewController/ContainerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ContainerViewController.h 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ContainerViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SwitchViewController/ContainerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ContainerViewController.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import "ContainerViewController.h" 10 | #import "FirstViewController.h" 11 | #import "SecondViewController.h" 12 | 13 | 14 | @interface ContainerViewController () 15 | 16 | @property (nonatomic, strong) UISegmentedControl *segment; 17 | 18 | @property (nonatomic, strong) UIViewController *currentViewController; 19 | 20 | @property (nonatomic) NSInteger segmentIndex; 21 | 22 | @end 23 | 24 | @implementation ContainerViewController 25 | 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | [self configura]; 29 | [self createView]; 30 | // Do any additional setup after loading the view. 31 | } 32 | 33 | - (void)configura { 34 | self.segmentIndex = 0; 35 | } 36 | 37 | - (void)createView { 38 | self.navigationItem.titleView = self.segment; 39 | for (UIViewController *vc in [self makeChildViewController]) { 40 | [self addChildViewController:vc]; 41 | } 42 | /* 这种方法添加 view 不会触发 first 的 viewwillappear 等一系列方法 43 | FirstViewController *first = [FirstViewController new]; 44 | first.view.frame = self.view.bounds; 45 | [self.view addSubview:first.view]; 46 | */ 47 | self.currentViewController = self.childViewControllers[self.segmentIndex]; 48 | self.currentViewController.view.frame = self.view.bounds; 49 | [self.view addSubview:self.currentViewController.view]; 50 | [self.currentViewController didMoveToParentViewController:self]; 51 | } 52 | 53 | - (UISegmentedControl *)segment { 54 | if (!_segment) { 55 | self.segment = [[UISegmentedControl alloc] initWithItems:@[@"第一页",@"第二页"]]; 56 | [self.segment setSelectedSegmentIndex:self.segmentIndex]; 57 | [self.segment addTarget:self action:@selector(switchVC:) forControlEvents:UIControlEventValueChanged]; 58 | } 59 | return _segment; 60 | } 61 | 62 | - (NSArray *)makeChildViewController { 63 | FirstViewController *first = [FirstViewController new]; 64 | SecondViewController *second = [SecondViewController new]; 65 | return @[first,second]; 66 | } 67 | - (void)switchVC:(UISegmentedControl *)sender { 68 | //分两种情况 69 | 70 | // case 0 当 container 是一个自定义的 ViewController 容器类或者是 NavigationController时,用下面的方法来触发 view 的 appearance callbacks 71 | 72 | [self.currentViewController willMoveToParentViewController:nil]; 73 | [self.currentViewController.view removeFromSuperview]; 74 | UIViewController *vc = self.childViewControllers[sender.selectedSegmentIndex]; 75 | vc.view.frame = self.view.bounds; 76 | [self.view addSubview:vc.view]; 77 | [vc didMoveToParentViewController:self]; 78 | self.currentViewController = vc; 79 | 80 | 81 | // case 1 当 container 是一个 Scrollview 的时候,也就是说如果每次滚动到新的页面都需要触发 view 的 appearance callbacks 的话,用下面的方法 82 | /* 83 | [self.currentViewController beginAppearanceTransition:NO animated:YES]; 84 | UIViewController *vc = self.childViewControllers[sender.selectedSegmentIndex]; 85 | [vc beginAppearanceTransition:YES animated:YES]; 86 | [self.currentViewController endAppearanceTransition]; 87 | [vc endAppearanceTransition]; 88 | self.currentViewController = vc; 89 | */ 90 | 91 | } 92 | - (void)didReceiveMemoryWarning { 93 | [super didReceiveMemoryWarning]; 94 | // Dispose of any resources that can be recreated. 95 | } 96 | 97 | /* 98 | #pragma mark - Navigation 99 | 100 | // In a storyboard-based application, you will often want to do a little preparation before navigation 101 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 102 | // Get the new view controller using [segue destinationViewController]. 103 | // Pass the selected object to the new view controller. 104 | } 105 | */ 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /SwitchViewController/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SwitchViewController/FirstViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import "FirstViewController.h" 10 | 11 | @interface FirstViewController () 12 | 13 | @end 14 | 15 | @implementation FirstViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | self.view.backgroundColor = [UIColor blueColor]; 20 | // Do any additional setup after loading the view. 21 | } 22 | - (void)viewWillAppear:(BOOL)animated { 23 | NSLog(@"1 viewWillAppear"); 24 | } 25 | - (void)viewDidAppear:(BOOL)animated { 26 | NSLog(@"1 viewDidAppear"); 27 | } 28 | - (void)viewWillDisappear:(BOOL)animated { 29 | NSLog(@"1 viewWillDisappear"); 30 | } 31 | - (void)viewDidDisappear:(BOOL)animated { 32 | NSLog(@"1 viewDidDisappear"); 33 | } 34 | - (void)didReceiveMemoryWarning { 35 | [super didReceiveMemoryWarning]; 36 | // Dispose of any resources that can be recreated. 37 | } 38 | 39 | /* 40 | #pragma mark - Navigation 41 | 42 | // In a storyboard-based application, you will often want to do a little preparation before navigation 43 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 44 | // Get the new view controller using [segue destinationViewController]. 45 | // Pass the selected object to the new view controller. 46 | } 47 | */ 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /SwitchViewController/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /SwitchViewController/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SwitchViewController/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | 11 | @interface SecondViewController () 12 | 13 | @end 14 | 15 | @implementation SecondViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | self.view.backgroundColor = [UIColor redColor]; 20 | // Do any additional setup after loading the view. 21 | } 22 | - (void)viewWillAppear:(BOOL)animated { 23 | NSLog(@"2 viewWillAppear"); 24 | } 25 | - (void)viewDidAppear:(BOOL)animated { 26 | NSLog(@"2 viewDidAppear"); 27 | } 28 | - (void)viewWillDisappear:(BOOL)animated { 29 | NSLog(@"2 viewWillDisappear"); 30 | } 31 | - (void)viewDidDisappear:(BOOL)animated { 32 | NSLog(@"2 viewDidDisappear"); 33 | } 34 | - (void)didReceiveMemoryWarning { 35 | [super didReceiveMemoryWarning]; 36 | // Dispose of any resources that can be recreated. 37 | } 38 | 39 | /* 40 | #pragma mark - Navigation 41 | 42 | // In a storyboard-based application, you will often want to do a little preparation before navigation 43 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 44 | // Get the new view controller using [segue destinationViewController]. 45 | // Pass the selected object to the new view controller. 46 | } 47 | */ 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /SwitchViewController/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /SwitchViewController/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "ContainerViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | 22 | 23 | // Do any additional setup after loading the view, typically from a nib. 24 | } 25 | - (IBAction)pushToNextViewController:(id)sender { 26 | ContainerViewController *container = [ContainerViewController new]; 27 | [self.navigationController pushViewController:container animated:YES]; 28 | } 29 | 30 | - (void)didReceiveMemoryWarning { 31 | [super didReceiveMemoryWarning]; 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /SwitchViewController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SwitchViewController 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SwitchViewControllerTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SwitchViewControllerTests/SwitchViewControllerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SwitchViewControllerTests.m 3 | // SwitchViewControllerTests 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SwitchViewControllerTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SwitchViewControllerTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /SwitchViewControllerUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SwitchViewControllerUITests/SwitchViewControllerUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SwitchViewControllerUITests.m 3 | // SwitchViewControllerUITests 4 | // 5 | // Created by JuLiaoyuan on 16/8/30. 6 | // Copyright © 2016年 Spark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SwitchViewControllerUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SwitchViewControllerUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------