├── .gitignore ├── LICENSE ├── PageViewController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── tom.xcuserdatad │ └── xcschemes │ ├── PageViewController.xcscheme │ └── xcschememanagement.plist ├── PageViewController ├── AppDelegate.h ├── AppDelegate.m ├── CustomPagerViewController.h ├── CustomPagerViewController.m ├── PageViewController-Info.plist ├── PageViewController-Prefix.pch ├── PagerViewController.h ├── PagerViewController.m ├── en.lproj │ ├── InfoPlist.strings │ └── MainStoryboard.storyboard └── main.m └── README /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | 4 | PageViewController.xcodeproj/project.xcworkspace/xcuserdata/tom.xcuserdatad/UserInterfaceState.xcuserstate 5 | 6 | PageViewController.xcodeproj/project.xcworkspace/xcuserdata/tom.xcuserdatad/WorkspaceSettings.xcsettings 7 | 8 | PageViewController.xcodeproj/xcuserdata/tom.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | Anyone is free to copy, modify, publish, use, compile, sell, or 3 | distribute this software, either in source code form or as a compiled 4 | binary, for any purpose, commercial or non-commercial, and by any 5 | means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors 8 | of this software dedicate any and all copyright interest in the 9 | software to the public domain. We make this dedication for the benefit 10 | of the public at large and to the detriment of our heirs and 11 | successors. We intend this dedication to be an overt act of 12 | relinquishment in perpetuity of all present and future rights to this 13 | software under copyright law. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 | OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /PageViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E2CC669214BDBB9D00D97F3C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2CC669114BDBB9D00D97F3C /* UIKit.framework */; }; 11 | E2CC669414BDBB9D00D97F3C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2CC669314BDBB9D00D97F3C /* Foundation.framework */; }; 12 | E2CC669614BDBB9D00D97F3C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2CC669514BDBB9D00D97F3C /* CoreGraphics.framework */; }; 13 | E2CC669C14BDBB9D00D97F3C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E2CC669A14BDBB9D00D97F3C /* InfoPlist.strings */; }; 14 | E2CC669E14BDBB9E00D97F3C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E2CC669D14BDBB9E00D97F3C /* main.m */; }; 15 | E2CC66A214BDBB9E00D97F3C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2CC66A114BDBB9E00D97F3C /* AppDelegate.m */; }; 16 | E2CC66A514BDBB9E00D97F3C /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2CC66A314BDBB9E00D97F3C /* MainStoryboard.storyboard */; }; 17 | E2CC66A814BDBB9E00D97F3C /* PagerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2CC66A714BDBB9E00D97F3C /* PagerViewController.m */; }; 18 | E2CC66B014BDF93D00D97F3C /* CustomPagerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2CC66AF14BDF93D00D97F3C /* CustomPagerViewController.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | E2CC668D14BDBB9D00D97F3C /* PageViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PageViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | E2CC669114BDBB9D00D97F3C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 24 | E2CC669314BDBB9D00D97F3C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 25 | E2CC669514BDBB9D00D97F3C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 26 | E2CC669914BDBB9D00D97F3C /* PageViewController-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PageViewController-Info.plist"; sourceTree = ""; }; 27 | E2CC669B14BDBB9D00D97F3C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 28 | E2CC669D14BDBB9E00D97F3C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 29 | E2CC669F14BDBB9E00D97F3C /* PageViewController-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PageViewController-Prefix.pch"; sourceTree = ""; }; 30 | E2CC66A014BDBB9E00D97F3C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 31 | E2CC66A114BDBB9E00D97F3C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 32 | E2CC66A414BDBB9E00D97F3C /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = ""; }; 33 | E2CC66A614BDBB9E00D97F3C /* PagerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PagerViewController.h; sourceTree = ""; }; 34 | E2CC66A714BDBB9E00D97F3C /* PagerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PagerViewController.m; sourceTree = ""; }; 35 | E2CC66AE14BDF93D00D97F3C /* CustomPagerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPagerViewController.h; sourceTree = ""; }; 36 | E2CC66AF14BDF93D00D97F3C /* CustomPagerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPagerViewController.m; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | E2CC668A14BDBB9D00D97F3C /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | E2CC669214BDBB9D00D97F3C /* UIKit.framework in Frameworks */, 45 | E2CC669414BDBB9D00D97F3C /* Foundation.framework in Frameworks */, 46 | E2CC669614BDBB9D00D97F3C /* CoreGraphics.framework in Frameworks */, 47 | ); 48 | runOnlyForDeploymentPostprocessing = 0; 49 | }; 50 | /* End PBXFrameworksBuildPhase section */ 51 | 52 | /* Begin PBXGroup section */ 53 | E2CC668214BDBB9D00D97F3C = { 54 | isa = PBXGroup; 55 | children = ( 56 | E2CC669714BDBB9D00D97F3C /* PageViewController */, 57 | E2CC669014BDBB9D00D97F3C /* Frameworks */, 58 | E2CC668E14BDBB9D00D97F3C /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | E2CC668E14BDBB9D00D97F3C /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | E2CC668D14BDBB9D00D97F3C /* PageViewController.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | E2CC669014BDBB9D00D97F3C /* Frameworks */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | E2CC669114BDBB9D00D97F3C /* UIKit.framework */, 74 | E2CC669314BDBB9D00D97F3C /* Foundation.framework */, 75 | E2CC669514BDBB9D00D97F3C /* CoreGraphics.framework */, 76 | ); 77 | name = Frameworks; 78 | sourceTree = ""; 79 | }; 80 | E2CC669714BDBB9D00D97F3C /* PageViewController */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | E2CC66A014BDBB9E00D97F3C /* AppDelegate.h */, 84 | E2CC66A114BDBB9E00D97F3C /* AppDelegate.m */, 85 | E2CC66A314BDBB9E00D97F3C /* MainStoryboard.storyboard */, 86 | E2CC66A614BDBB9E00D97F3C /* PagerViewController.h */, 87 | E2CC66A714BDBB9E00D97F3C /* PagerViewController.m */, 88 | E2CC66AE14BDF93D00D97F3C /* CustomPagerViewController.h */, 89 | E2CC66AF14BDF93D00D97F3C /* CustomPagerViewController.m */, 90 | E2CC669814BDBB9D00D97F3C /* Supporting Files */, 91 | ); 92 | path = PageViewController; 93 | sourceTree = ""; 94 | }; 95 | E2CC669814BDBB9D00D97F3C /* Supporting Files */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | E2CC669914BDBB9D00D97F3C /* PageViewController-Info.plist */, 99 | E2CC669A14BDBB9D00D97F3C /* InfoPlist.strings */, 100 | E2CC669D14BDBB9E00D97F3C /* main.m */, 101 | E2CC669F14BDBB9E00D97F3C /* PageViewController-Prefix.pch */, 102 | ); 103 | name = "Supporting Files"; 104 | sourceTree = ""; 105 | }; 106 | /* End PBXGroup section */ 107 | 108 | /* Begin PBXNativeTarget section */ 109 | E2CC668C14BDBB9D00D97F3C /* PageViewController */ = { 110 | isa = PBXNativeTarget; 111 | buildConfigurationList = E2CC66AB14BDBB9E00D97F3C /* Build configuration list for PBXNativeTarget "PageViewController" */; 112 | buildPhases = ( 113 | E2CC668914BDBB9D00D97F3C /* Sources */, 114 | E2CC668A14BDBB9D00D97F3C /* Frameworks */, 115 | E2CC668B14BDBB9D00D97F3C /* Resources */, 116 | ); 117 | buildRules = ( 118 | ); 119 | dependencies = ( 120 | ); 121 | name = PageViewController; 122 | productName = PageViewController; 123 | productReference = E2CC668D14BDBB9D00D97F3C /* PageViewController.app */; 124 | productType = "com.apple.product-type.application"; 125 | }; 126 | /* End PBXNativeTarget section */ 127 | 128 | /* Begin PBXProject section */ 129 | E2CC668414BDBB9D00D97F3C /* Project object */ = { 130 | isa = PBXProject; 131 | attributes = { 132 | LastUpgradeCheck = 0430; 133 | }; 134 | buildConfigurationList = E2CC668714BDBB9D00D97F3C /* Build configuration list for PBXProject "PageViewController" */; 135 | compatibilityVersion = "Xcode 3.2"; 136 | developmentRegion = English; 137 | hasScannedForEncodings = 0; 138 | knownRegions = ( 139 | en, 140 | ); 141 | mainGroup = E2CC668214BDBB9D00D97F3C; 142 | productRefGroup = E2CC668E14BDBB9D00D97F3C /* Products */; 143 | projectDirPath = ""; 144 | projectRoot = ""; 145 | targets = ( 146 | E2CC668C14BDBB9D00D97F3C /* PageViewController */, 147 | ); 148 | }; 149 | /* End PBXProject section */ 150 | 151 | /* Begin PBXResourcesBuildPhase section */ 152 | E2CC668B14BDBB9D00D97F3C /* Resources */ = { 153 | isa = PBXResourcesBuildPhase; 154 | buildActionMask = 2147483647; 155 | files = ( 156 | E2CC669C14BDBB9D00D97F3C /* InfoPlist.strings in Resources */, 157 | E2CC66A514BDBB9E00D97F3C /* MainStoryboard.storyboard in Resources */, 158 | ); 159 | runOnlyForDeploymentPostprocessing = 0; 160 | }; 161 | /* End PBXResourcesBuildPhase section */ 162 | 163 | /* Begin PBXSourcesBuildPhase section */ 164 | E2CC668914BDBB9D00D97F3C /* Sources */ = { 165 | isa = PBXSourcesBuildPhase; 166 | buildActionMask = 2147483647; 167 | files = ( 168 | E2CC669E14BDBB9E00D97F3C /* main.m in Sources */, 169 | E2CC66A214BDBB9E00D97F3C /* AppDelegate.m in Sources */, 170 | E2CC66A814BDBB9E00D97F3C /* PagerViewController.m in Sources */, 171 | E2CC66B014BDF93D00D97F3C /* CustomPagerViewController.m in Sources */, 172 | ); 173 | runOnlyForDeploymentPostprocessing = 0; 174 | }; 175 | /* End PBXSourcesBuildPhase section */ 176 | 177 | /* Begin PBXVariantGroup section */ 178 | E2CC669A14BDBB9D00D97F3C /* InfoPlist.strings */ = { 179 | isa = PBXVariantGroup; 180 | children = ( 181 | E2CC669B14BDBB9D00D97F3C /* en */, 182 | ); 183 | name = InfoPlist.strings; 184 | sourceTree = ""; 185 | }; 186 | E2CC66A314BDBB9E00D97F3C /* MainStoryboard.storyboard */ = { 187 | isa = PBXVariantGroup; 188 | children = ( 189 | E2CC66A414BDBB9E00D97F3C /* en */, 190 | ); 191 | name = MainStoryboard.storyboard; 192 | sourceTree = ""; 193 | }; 194 | /* End PBXVariantGroup section */ 195 | 196 | /* Begin XCBuildConfiguration section */ 197 | E2CC66A914BDBB9E00D97F3C /* Debug */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 202 | CLANG_ENABLE_OBJC_ARC = YES; 203 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 204 | COPY_PHASE_STRIP = NO; 205 | GCC_C_LANGUAGE_STANDARD = gnu99; 206 | GCC_DYNAMIC_NO_PIC = NO; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 213 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 214 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 216 | GCC_WARN_UNUSED_VARIABLE = YES; 217 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 218 | SDKROOT = iphoneos; 219 | }; 220 | name = Debug; 221 | }; 222 | E2CC66AA14BDBB9E00D97F3C /* Release */ = { 223 | isa = XCBuildConfiguration; 224 | buildSettings = { 225 | ALWAYS_SEARCH_USER_PATHS = NO; 226 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 229 | COPY_PHASE_STRIP = YES; 230 | GCC_C_LANGUAGE_STANDARD = gnu99; 231 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 232 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 233 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 5.1; 236 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 237 | SDKROOT = iphoneos; 238 | VALIDATE_PRODUCT = YES; 239 | }; 240 | name = Release; 241 | }; 242 | E2CC66AC14BDBB9E00D97F3C /* Debug */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 246 | GCC_PREFIX_HEADER = "PageViewController/PageViewController-Prefix.pch"; 247 | INFOPLIST_FILE = "PageViewController/PageViewController-Info.plist"; 248 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 249 | PRODUCT_NAME = "$(TARGET_NAME)"; 250 | WRAPPER_EXTENSION = app; 251 | }; 252 | name = Debug; 253 | }; 254 | E2CC66AD14BDBB9E00D97F3C /* Release */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 258 | GCC_PREFIX_HEADER = "PageViewController/PageViewController-Prefix.pch"; 259 | INFOPLIST_FILE = "PageViewController/PageViewController-Info.plist"; 260 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 261 | PRODUCT_NAME = "$(TARGET_NAME)"; 262 | WRAPPER_EXTENSION = app; 263 | }; 264 | name = Release; 265 | }; 266 | /* End XCBuildConfiguration section */ 267 | 268 | /* Begin XCConfigurationList section */ 269 | E2CC668714BDBB9D00D97F3C /* Build configuration list for PBXProject "PageViewController" */ = { 270 | isa = XCConfigurationList; 271 | buildConfigurations = ( 272 | E2CC66A914BDBB9E00D97F3C /* Debug */, 273 | E2CC66AA14BDBB9E00D97F3C /* Release */, 274 | ); 275 | defaultConfigurationIsVisible = 0; 276 | defaultConfigurationName = Release; 277 | }; 278 | E2CC66AB14BDBB9E00D97F3C /* Build configuration list for PBXNativeTarget "PageViewController" */ = { 279 | isa = XCConfigurationList; 280 | buildConfigurations = ( 281 | E2CC66AC14BDBB9E00D97F3C /* Debug */, 282 | E2CC66AD14BDBB9E00D97F3C /* Release */, 283 | ); 284 | defaultConfigurationIsVisible = 0; 285 | defaultConfigurationName = Release; 286 | }; 287 | /* End XCConfigurationList section */ 288 | }; 289 | rootObject = E2CC668414BDBB9D00D97F3C /* Project object */; 290 | } 291 | -------------------------------------------------------------------------------- /PageViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PageViewController.xcodeproj/xcuserdata/tom.xcuserdatad/xcschemes/PageViewController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 49 | 50 | 56 | 57 | 58 | 59 | 60 | 61 | 67 | 68 | 74 | 75 | 76 | 77 | 79 | 80 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /PageViewController.xcodeproj/xcuserdata/tom.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | PageViewController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E2CC668C14BDBB9D00D97F3C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /PageViewController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import 9 | 10 | @interface AppDelegate : UIResponder 11 | 12 | @property (strong, nonatomic) UIWindow *window; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /PageViewController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import "AppDelegate.h" 9 | 10 | @implementation AppDelegate 11 | 12 | @synthesize window = _window; 13 | 14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 15 | { 16 | // Override point for customization after application launch. 17 | return YES; 18 | } 19 | 20 | - (void)applicationWillResignActive:(UIApplication *)application 21 | { 22 | // 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. 23 | // 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. 24 | } 25 | 26 | - (void)applicationDidEnterBackground:(UIApplication *)application 27 | { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | - (void)applicationWillEnterForeground:(UIApplication *)application 33 | { 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 | { 39 | // 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. 40 | } 41 | 42 | - (void)applicationWillTerminate:(UIApplication *)application 43 | { 44 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /PageViewController/CustomPagerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomPageViewController.h 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import "PagerViewController.h" 9 | 10 | @interface CustomPagerViewController : PagerViewController 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /PageViewController/CustomPagerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomPageViewController.m 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import "CustomPagerViewController.h" 9 | 10 | @interface CustomPagerViewController () 11 | 12 | @end 13 | 14 | @implementation CustomPagerViewController 15 | 16 | - (void)viewDidLoad 17 | { 18 | // Do any additional setup after loading the view, typically from a nib. 19 | [super viewDidLoad]; 20 | 21 | [self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]]; 22 | [self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View2"]]; 23 | [self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View3"]]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /PageViewController/PageViewController-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.wannabegeek.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /PageViewController/PageViewController-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'PageViewController' target in the 'PageViewController' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /PageViewController/PagerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import 9 | 10 | @interface PagerViewController : UIViewController 11 | 12 | @property (nonatomic, strong) IBOutlet UIScrollView *scrollView; 13 | @property (nonatomic, strong) IBOutlet UIPageControl *pageControl; 14 | 15 | - (IBAction)changePage:(id)sender; 16 | 17 | - (void)previousPage; 18 | - (void)nextPage; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /PageViewController/PagerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import "PagerViewController.h" 9 | 10 | @interface PagerViewController () 11 | @property (assign) BOOL pageControlUsed; 12 | @property (assign) NSUInteger page; 13 | @property (assign) BOOL rotating; 14 | - (void)loadScrollViewWithPage:(int)page; 15 | @end 16 | 17 | @implementation PagerViewController 18 | 19 | @synthesize scrollView; 20 | @synthesize pageControl; 21 | @synthesize pageControlUsed = _pageControlUsed; 22 | @synthesize page = _page; 23 | @synthesize rotating = _rotating; 24 | 25 | - (void)viewDidLoad 26 | { 27 | [super viewDidLoad]; 28 | // Do any additional setup after loading the view, typically from a nib. 29 | [self.scrollView setPagingEnabled:YES]; 30 | [self.scrollView setScrollEnabled:YES]; 31 | [self.scrollView setShowsHorizontalScrollIndicator:NO]; 32 | [self.scrollView setShowsVerticalScrollIndicator:NO]; 33 | [self.scrollView setDelegate:self]; 34 | } 35 | 36 | - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers { 37 | return NO; 38 | } 39 | 40 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 41 | { 42 | return YES; 43 | } 44 | 45 | - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 46 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 47 | [viewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 48 | _rotating = YES; 49 | } 50 | 51 | - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 52 | 53 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 54 | [viewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 55 | 56 | self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.childViewControllers count], scrollView.frame.size.height); 57 | NSUInteger page = 0; 58 | for (viewController in self.childViewControllers) { 59 | CGRect frame = self.scrollView.frame; 60 | frame.origin.x = frame.size.width * page; 61 | frame.origin.y = 0; 62 | viewController.view.frame = frame; 63 | page++; 64 | } 65 | 66 | CGRect frame = self.scrollView.frame; 67 | frame.origin.x = frame.size.width * _page; 68 | frame.origin.y = 0; 69 | [self.scrollView scrollRectToVisible:frame animated:NO]; 70 | 71 | } 72 | 73 | - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 74 | _rotating = NO; 75 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 76 | [viewController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 77 | } 78 | 79 | - (void)viewWillAppear:(BOOL)animated { 80 | [super viewWillAppear:animated]; 81 | 82 | for (NSUInteger i =0; i < [self.childViewControllers count]; i++) { 83 | [self loadScrollViewWithPage:i]; 84 | } 85 | 86 | self.pageControl.currentPage = 0; 87 | _page = 0; 88 | [self.pageControl setNumberOfPages:[self.childViewControllers count]]; 89 | 90 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 91 | if (viewController.view.superview != nil) { 92 | [viewController viewWillAppear:animated]; 93 | } 94 | 95 | self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [self.childViewControllers count], scrollView.frame.size.height); 96 | } 97 | 98 | - (void)viewDidAppear:(BOOL)animated { 99 | [super viewDidAppear:animated]; 100 | 101 | if ([self.childViewControllers count]) { 102 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 103 | if (viewController.view.superview != nil) { 104 | [viewController viewDidAppear:animated]; 105 | } 106 | } 107 | } 108 | 109 | - (void)viewWillDisappear:(BOOL)animated { 110 | if ([self.childViewControllers count]) { 111 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 112 | if (viewController.view.superview != nil) { 113 | [viewController viewWillDisappear:animated]; 114 | } 115 | } 116 | [super viewWillDisappear:animated]; 117 | } 118 | 119 | - (void)viewDidDisappear:(BOOL)animated { 120 | UIViewController *viewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 121 | if (viewController.view.superview != nil) { 122 | [viewController viewDidDisappear:animated]; 123 | } 124 | [super viewDidDisappear:animated]; 125 | } 126 | 127 | - (void)loadScrollViewWithPage:(int)page { 128 | if (page < 0) 129 | return; 130 | if (page >= [self.childViewControllers count]) 131 | return; 132 | 133 | // replace the placeholder if necessary 134 | UIViewController *controller = [self.childViewControllers objectAtIndex:page]; 135 | if (controller == nil) { 136 | return; 137 | } 138 | 139 | // add the controller's view to the scroll view 140 | if (controller.view.superview == nil) { 141 | CGRect frame = self.scrollView.frame; 142 | frame.origin.x = frame.size.width * page; 143 | frame.origin.y = 0; 144 | controller.view.frame = frame; 145 | [self.scrollView addSubview:controller.view]; 146 | } 147 | } 148 | 149 | - (void)previousPage { 150 | if (_page - 1 > 0) { 151 | 152 | // update the scroll view to the appropriate page 153 | CGRect frame = self.scrollView.frame; 154 | frame.origin.x = frame.size.width * (_page - 1); 155 | frame.origin.y = 0; 156 | 157 | UIViewController *oldViewController = [self.childViewControllers objectAtIndex:_page]; 158 | UIViewController *newViewController = [self.childViewControllers objectAtIndex:_page - 1]; 159 | [oldViewController viewWillDisappear:YES]; 160 | [newViewController viewWillAppear:YES]; 161 | 162 | [self.scrollView scrollRectToVisible:frame animated:YES]; 163 | 164 | self.pageControl.currentPage = _page - 1; 165 | // Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above. 166 | _pageControlUsed = YES; 167 | } 168 | } 169 | 170 | - (void)nextPage { 171 | if (_page + 1 > self.pageControl.numberOfPages) { 172 | 173 | // update the scroll view to the appropriate page 174 | CGRect frame = self.scrollView.frame; 175 | frame.origin.x = frame.size.width * (_page + 1); 176 | frame.origin.y = 0; 177 | 178 | UIViewController *oldViewController = [self.childViewControllers objectAtIndex:_page]; 179 | UIViewController *newViewController = [self.childViewControllers objectAtIndex:_page + 1]; 180 | [oldViewController viewWillDisappear:YES]; 181 | [newViewController viewWillAppear:YES]; 182 | 183 | [self.scrollView scrollRectToVisible:frame animated:YES]; 184 | 185 | self.pageControl.currentPage = _page + 1; 186 | // Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above. 187 | _pageControlUsed = YES; 188 | } 189 | } 190 | 191 | - (IBAction)changePage:(id)sender { 192 | int page = ((UIPageControl *)sender).currentPage; 193 | 194 | // update the scroll view to the appropriate page 195 | CGRect frame = self.scrollView.frame; 196 | frame.origin.x = frame.size.width * page; 197 | frame.origin.y = 0; 198 | 199 | UIViewController *oldViewController = [self.childViewControllers objectAtIndex:_page]; 200 | UIViewController *newViewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 201 | [oldViewController viewWillDisappear:YES]; 202 | [newViewController viewWillAppear:YES]; 203 | 204 | [self.scrollView scrollRectToVisible:frame animated:YES]; 205 | 206 | // Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above. 207 | _pageControlUsed = YES; 208 | } 209 | 210 | - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { 211 | UIViewController *oldViewController = [self.childViewControllers objectAtIndex:_page]; 212 | UIViewController *newViewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 213 | [oldViewController viewDidDisappear:YES]; 214 | [newViewController viewDidAppear:YES]; 215 | 216 | _page = self.pageControl.currentPage; 217 | } 218 | 219 | #pragma mark - 220 | #pragma mark UIScrollViewDelegate methods 221 | 222 | - (void)scrollViewDidScroll:(UIScrollView *)sender { 223 | // We don't want a "feedback loop" between the UIPageControl and the scroll delegate in 224 | // which a scroll event generated from the user hitting the page control triggers updates from 225 | // the delegate method. We use a boolean to disable the delegate logic when the page control is used. 226 | if (_pageControlUsed || _rotating) { 227 | // do nothing - the scroll was initiated from the page control, not the user dragging 228 | return; 229 | } 230 | 231 | // Switch the indicator when more than 50% of the previous/next page is visible 232 | CGFloat pageWidth = self.scrollView.frame.size.width; 233 | int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 234 | if (self.pageControl.currentPage != page) { 235 | UIViewController *oldViewController = [self.childViewControllers objectAtIndex:self.pageControl.currentPage]; 236 | UIViewController *newViewController = [self.childViewControllers objectAtIndex:page]; 237 | [oldViewController viewWillDisappear:YES]; 238 | [newViewController viewWillAppear:YES]; 239 | self.pageControl.currentPage = page; 240 | [oldViewController viewDidDisappear:YES]; 241 | [newViewController viewDidAppear:YES]; 242 | _page = page; 243 | } 244 | } 245 | 246 | // At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl 247 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 248 | _pageControlUsed = NO; 249 | } 250 | 251 | // At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl 252 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 253 | _pageControlUsed = NO; 254 | } 255 | 256 | @end 257 | -------------------------------------------------------------------------------- /PageViewController/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /PageViewController/en.lproj/MainStoryboard.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 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /PageViewController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // PageViewController 4 | // 5 | // Created by Tom Fewster on 11/01/2012. 6 | // 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | @autoreleasepool { 15 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | For more information see http://www.wannabegeek.com/?p=168 2 | --------------------------------------------------------------------------------