@@ -34,24 +34,24 @@ @implementation SCRootViewController
3434
3535- (void )viewDidLoad
3636{
37- [super viewDidLoad ];
38-
39- self.viewControllers = [NSMutableArray array ];
40- for (int i=0 ; i < kDefaultNumberOfPages ; i++) {
41- [self .viewControllers addObject: [NSNull null ]];
42- }
43-
44- self.pageViewController = [[SCPageViewController alloc ] init ];
45- [self .pageViewController setDataSource: self ];
46- [self .pageViewController setDelegate: self ];
47-
48- [self .pageViewController setLayouter: [[SCPageLayouter alloc ] init ] animated: NO completion: nil ];
49- [self .pageViewController setEasingFunction: [SCEasingFunction easingFunctionWithType: SCEasingFunctionTypeLinear]];
37+ [super viewDidLoad ];
5038
51- [self addChildViewController: self .pageViewController];
52- [self .pageViewController.view setFrame: self .view.bounds];
53- [self .view addSubview: self .pageViewController.view];
54- [self .pageViewController didMoveToParentViewController: self ];
39+ self.viewControllers = [NSMutableArray array ];
40+ for (int i=0 ; i < kDefaultNumberOfPages ; i++) {
41+ [self .viewControllers addObject: [NSNull null ]];
42+ }
43+
44+ self.pageViewController = [[SCPageViewController alloc ] init ];
45+ [self .pageViewController setDataSource: self ];
46+ [self .pageViewController setDelegate: self ];
47+
48+ [self .pageViewController setLayouter: [[SCPageLayouter alloc ] init ] animated: NO completion: nil ];
49+ [self .pageViewController setEasingFunction: [SCEasingFunction easingFunctionWithType: SCEasingFunctionTypeLinear]];
50+
51+ [self addChildViewController: self .pageViewController];
52+ [self .pageViewController.view setFrame: self .view.bounds];
53+ [self .view addSubview: self .pageViewController.view];
54+ [self .pageViewController didMoveToParentViewController: self ];
5555
5656 [self _updateViewControllerDetails ];
5757}
@@ -60,23 +60,23 @@ - (void)viewDidLoad
6060
6161- (NSUInteger )numberOfPagesInPageViewController : (SCPageViewController *)pageViewController
6262{
63- return self.viewControllers .count ;
63+ return self.viewControllers .count ;
6464}
6565
6666- (UIViewController *)pageViewController : (SCPageViewController *)pageViewController viewControllerForPageAtIndex : (NSUInteger )pageIndex
6767{
68- SCMainViewController *viewController = self.viewControllers [pageIndex];
69-
70- if ([viewController isEqual: [NSNull null ]]) {
71- viewController = [[SCMainViewController alloc ] init ];
72- [viewController.view setFrame: self .view.bounds];
73- [viewController setDelegate: self ];
74- [viewController.contentView setBackgroundColor: [UIColor randomColor ]];
75-
76- [self .viewControllers replaceObjectAtIndex: pageIndex withObject: viewController];
77- }
78-
79- return viewController;
68+ SCMainViewController *viewController = self.viewControllers [pageIndex];
69+
70+ if ([viewController isEqual: [NSNull null ]]) {
71+ viewController = [[SCMainViewController alloc ] init ];
72+ [viewController.view setFrame: self .view.bounds];
73+ [viewController setDelegate: self ];
74+ [viewController.contentView setBackgroundColor: [UIColor randomColor ]];
75+
76+ [self .viewControllers replaceObjectAtIndex: pageIndex withObject: viewController];
77+ }
78+
79+ return viewController;
8080}
8181
8282- (NSUInteger )initialPageInPageViewController : (SCPageViewController *)pageViewController
@@ -88,127 +88,127 @@ - (NSUInteger)initialPageInPageViewController:(SCPageViewController *)pageViewCo
8888
8989- (void )pageViewController : (SCPageViewController *)pageViewController didNavigateToOffset : (CGPoint)offset
9090{
91- [self _updateViewControllerDetails ];
91+ [self _updateViewControllerDetails ];
9292}
9393
9494#pragma mark - SCMainViewControllerDelegate
9595
9696- (void )mainViewControllerDidChangeLayouterType : (SCMainViewController *)mainViewController
9797{
98- static NSDictionary *typeToLayouter;
99- static dispatch_once_t onceToken;
100- dispatch_once (&onceToken, ^{
101- typeToLayouter = (@{@(SCPageLayouterTypePlain) : [SCPageLayouter class ],
102- @(SCPageLayouterTypeSliding) : [SCSlidingPageLayouter class ],
103- @(SCPageLayouterTypeParallax) : [SCParallaxPageLayouter class ],
104- @(SCPageLayouterTypeCards) : [SCCardsPageLayouter class ]});
105- });
106-
107- id <SCPageLayouterProtocol> pageLayouter = [[typeToLayouter[@(mainViewController.layouterType)] alloc ] init ];
108- [self .pageViewController setLayouter: pageLayouter animated: YES completion: nil ];
109-
110- [self _updateViewControllerDetails ];
98+ static NSDictionary *typeToLayouter;
99+ static dispatch_once_t onceToken;
100+ dispatch_once (&onceToken, ^{
101+ typeToLayouter = (@{@(SCPageLayouterTypePlain) : [SCPageLayouter class ],
102+ @(SCPageLayouterTypeSliding) : [SCSlidingPageLayouter class ],
103+ @(SCPageLayouterTypeParallax) : [SCParallaxPageLayouter class ],
104+ @(SCPageLayouterTypeCards) : [SCCardsPageLayouter class ]});
105+ });
106+
107+ id <SCPageLayouterProtocol> pageLayouter = [[typeToLayouter[@(mainViewController.layouterType)] alloc ] init ];
108+ [self .pageViewController setLayouter: pageLayouter animated: YES completion: nil ];
109+
110+ [self _updateViewControllerDetails ];
111111}
112112
113113- (void )mainViewControllerDidChangeAnimationType : (SCMainViewController *)mainViewController
114114{
115- [self .pageViewController setEasingFunction: [SCEasingFunction easingFunctionWithType: mainViewController.easingFunctionType]];
116- self.selectedEasingFunctionType = mainViewController.easingFunctionType ;
117-
118- [self _updateViewControllerDetails ];
115+ [self .pageViewController setEasingFunction: [SCEasingFunction easingFunctionWithType: mainViewController.easingFunctionType]];
116+ self.selectedEasingFunctionType = mainViewController.easingFunctionType ;
117+
118+ [self _updateViewControllerDetails ];
119119}
120120
121121- (void )mainViewControllerDidChangeAnimationDuration : (SCMainViewController *)mainViewController
122122{
123- [self .pageViewController setAnimationDuration: mainViewController.duration];
123+ [self .pageViewController setAnimationDuration: mainViewController.duration];
124124}
125125
126126- (void )mainViewControllerDidRequestNavigationToNextPage : (SCMainViewController *)mainViewController
127127{
128- [self .pageViewController navigateToPageAtIndex: MIN (self .pageViewController.numberOfPages, self .pageViewController.currentPage + 1 ) animated: YES completion: nil ];
128+ [self .pageViewController navigateToPageAtIndex: MIN (self .pageViewController.numberOfPages, self .pageViewController.currentPage + 1 ) animated: YES completion: nil ];
129129}
130130
131131- (void )mainViewControllerDidRequestNavigationToPreviousPage : (SCMainViewController *)mainViewController
132132{
133- [self .pageViewController navigateToPageAtIndex: MAX (0 , self .pageViewController.currentPage - 1 ) animated: YES completion: nil ];
133+ [self .pageViewController navigateToPageAtIndex: MAX (0 , self .pageViewController.currentPage - 1 ) animated: YES completion: nil ];
134134}
135135
136136- (void )mainViewControllerDidRequestPageInsertion : (SCMainViewController *)mainViewController
137137{
138- [self _insertPagesAtIndexes: [NSIndexSet indexSetWithIndex: [self .viewControllers indexOfObject: mainViewController]]];
139- [self _updateViewControllerDetails ];
138+ [self _insertPagesAtIndexes: [NSIndexSet indexSetWithIndex: [self .viewControllers indexOfObject: mainViewController]]];
139+ [self _updateViewControllerDetails ];
140140}
141141
142142- (void )mainViewControllerDidRequestPageDeletion : (SCMainViewController *)mainViewController
143143{
144- [self _deletePagesAtIndexes: [NSIndexSet indexSetWithIndex: [self .viewControllers indexOfObject: mainViewController]]];
145- [self _updateViewControllerDetails ];
144+ [self _deletePagesAtIndexes: [NSIndexSet indexSetWithIndex: [self .viewControllers indexOfObject: mainViewController]]];
145+ [self _updateViewControllerDetails ];
146146}
147147
148148#pragma mark - Private
149149
150150- (void )_reloadPagesAtIndexes : (NSIndexSet *)indexes
151151{
152- [indexes enumerateIndexesUsingBlock: ^(NSUInteger idx, BOOL *stop) {
153- [self .viewControllers replaceObjectAtIndex: idx withObject: [NSNull null ]];
154- }];
155-
156- [self .pageViewController reloadPagesAtIndexes: indexes animated: YES completion: nil ];
152+ [indexes enumerateIndexesUsingBlock: ^(NSUInteger idx, BOOL *stop) {
153+ [self .viewControllers replaceObjectAtIndex: idx withObject: [NSNull null ]];
154+ }];
155+
156+ [self .pageViewController reloadPagesAtIndexes: indexes animated: YES completion: nil ];
157157}
158158
159159- (void )_insertPagesAtIndexes : (NSIndexSet *)indexes
160160{
161- [indexes enumerateIndexesUsingBlock: ^(NSUInteger idx, BOOL *stop) {
162- [self .viewControllers insertObject: [NSNull null ] atIndex: idx];
163- }];
164-
165- [self .pageViewController insertPagesAtIndexes: indexes animated: YES completion: nil ];
161+ [indexes enumerateIndexesUsingBlock: ^(NSUInteger idx, BOOL *stop) {
162+ [self .viewControllers insertObject: [NSNull null ] atIndex: idx];
163+ }];
164+
165+ [self .pageViewController insertPagesAtIndexes: indexes animated: YES completion: nil ];
166166}
167167
168168- (void )_deletePagesAtIndexes : (NSIndexSet *)indexes
169169{
170- [indexes enumerateIndexesWithOptions: NSEnumerationReverse usingBlock: ^(NSUInteger idx, BOOL *stop) {
171- [self .viewControllers removeObjectAtIndex: idx];
172- }];
173-
174- [self .pageViewController deletePagesAtIndexes: indexes animated: YES completion: nil ];
170+ [indexes enumerateIndexesWithOptions: NSEnumerationReverse usingBlock: ^(NSUInteger idx, BOOL *stop) {
171+ [self .viewControllers removeObjectAtIndex: idx];
172+ }];
173+
174+ [self .pageViewController deletePagesAtIndexes: indexes animated: YES completion: nil ];
175175}
176176
177177- (void )_movePageFromIndex : (NSUInteger )fromIndex toIndex : (NSUInteger )toIndex
178178{
179- UIViewController *viewController = [self .viewControllers objectAtIndex: fromIndex];
180- [self .viewControllers removeObjectAtIndex: fromIndex];
181- [self .viewControllers insertObject: viewController atIndex: toIndex];
182-
183- [self .pageViewController movePageAtIndex: fromIndex toIndex: toIndex animated: YES completion: nil ];
179+ UIViewController *viewController = [self .viewControllers objectAtIndex: fromIndex];
180+ [self .viewControllers removeObjectAtIndex: fromIndex];
181+ [self .viewControllers insertObject: viewController atIndex: toIndex];
182+
183+ [self .pageViewController movePageAtIndex: fromIndex toIndex: toIndex animated: YES completion: nil ];
184184}
185185
186186- (void )_updateViewControllerDetails
187187{
188- [self .viewControllers enumerateObjectsUsingBlock: ^(SCMainViewController *controller, NSUInteger index, BOOL *stop) {
189-
190- if ([controller isEqual: [NSNull null ]]) {
191- return ;
192- }
193-
194- [controller.visiblePercentageLabel setText: [NSString stringWithFormat: @" %.2f%% " , [self .pageViewController visiblePercentageForViewController: controller]]];
195-
196- [controller.pageNumberLabel setText: [NSString stringWithFormat: @" Page %lu of %lu " , (unsigned long )index, (unsigned long )self .pageViewController.numberOfPages]];
197-
198- [controller setEasingFunctionType: self .selectedEasingFunctionType];
199- [controller setDuration: self .pageViewController.animationDuration];
200-
201- static NSDictionary *layouterToType;
202- static dispatch_once_t onceToken;
203- dispatch_once (&onceToken, ^{
204- layouterToType = (@{NSStringFromClass ([SCPageLayouter class ]) : @(SCPageLayouterTypePlain),
205- NSStringFromClass ([SCSlidingPageLayouter class ]) : @(SCPageLayouterTypeSliding),
206- NSStringFromClass ([SCParallaxPageLayouter class ]) : @(SCPageLayouterTypeParallax),
207- NSStringFromClass ([SCCardsPageLayouter class ]) : @(SCPageLayouterTypeCards)});
208- });
209-
210- [controller setLayouterType: (SCPageLayouterType)[layouterToType[NSStringFromClass ([self .pageViewController.layouter class ])] unsignedIntegerValue ]];
211- }];
188+ [self .viewControllers enumerateObjectsUsingBlock: ^(SCMainViewController *controller, NSUInteger index, BOOL *stop) {
189+
190+ if ([controller isEqual: [NSNull null ]]) {
191+ return ;
192+ }
193+
194+ [controller.visiblePercentageLabel setText: [NSString stringWithFormat: @" %.2f%% " , [self .pageViewController visiblePercentageForViewController: controller]]];
195+
196+ [controller.pageNumberLabel setText: [NSString stringWithFormat: @" Page %lu of %lu " , (unsigned long )index, (unsigned long )self .pageViewController.numberOfPages]];
197+
198+ [controller setEasingFunctionType: self .selectedEasingFunctionType];
199+ [controller setDuration: self .pageViewController.animationDuration];
200+
201+ static NSDictionary *layouterToType;
202+ static dispatch_once_t onceToken;
203+ dispatch_once (&onceToken, ^{
204+ layouterToType = (@{NSStringFromClass ([SCPageLayouter class ]) : @(SCPageLayouterTypePlain),
205+ NSStringFromClass ([SCSlidingPageLayouter class ]) : @(SCPageLayouterTypeSliding),
206+ NSStringFromClass ([SCParallaxPageLayouter class ]) : @(SCPageLayouterTypeParallax),
207+ NSStringFromClass ([SCCardsPageLayouter class ]) : @(SCPageLayouterTypeCards)});
208+ });
209+
210+ [controller setLayouterType: (SCPageLayouterType)[layouterToType[NSStringFromClass ([self .pageViewController.layouter class ])] unsignedIntegerValue ]];
211+ }];
212212}
213213
214214@end
0 commit comments