@@ -135,7 +135,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
135
135
/// The direction scrolling navigation occurs
136
136
open private( set) var navigationOrientation : EMPageViewControllerNavigationOrientation = . horizontal
137
137
138
- private var orientationIsHorizontal : Bool {
138
+ private var isOrientationHorizontal : Bool {
139
139
return self . navigationOrientation == . horizontal
140
140
}
141
141
@@ -147,8 +147,8 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
147
147
scrollView. scrollsToTop = false
148
148
scrollView. autoresizingMask = [ . flexibleTopMargin, . flexibleRightMargin, . flexibleBottomMargin, . flexibleLeftMargin]
149
149
scrollView. bounces = true
150
- scrollView. alwaysBounceHorizontal = self . orientationIsHorizontal
151
- scrollView. alwaysBounceVertical = !self . orientationIsHorizontal
150
+ scrollView. alwaysBounceHorizontal = self . isOrientationHorizontal
151
+ scrollView. alwaysBounceVertical = !self . isOrientationHorizontal
152
152
scrollView. translatesAutoresizingMaskIntoConstraints = true
153
153
scrollView. showsHorizontalScrollIndicator = false
154
154
scrollView. showsVerticalScrollIndicator = false
@@ -202,56 +202,57 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
202
202
self . afterViewController = viewController
203
203
self . layoutViews ( )
204
204
self . loadNewAdjoiningViewControllersOnFinish = true
205
- self . scrollForwardAnimated ( animated, completion: completion)
205
+ self . scrollForward ( animated : animated, completion: completion)
206
206
} else if ( direction == . reverse) {
207
207
self . beforeViewController = viewController
208
208
self . layoutViews ( )
209
209
self . loadNewAdjoiningViewControllersOnFinish = true
210
- self . scrollReverseAnimated ( animated, completion: completion)
210
+ self . scrollReverse ( animated : animated, completion: completion)
211
211
}
212
212
213
213
}
214
214
215
+
215
216
/**
216
- Transitions to the view controller right of the currently selected view controller in a horizontal orientation, or below the currently selected view controller in a vertical orientation. Also described as going to the next page.
217
-
218
- - parameter animated: A Boolean whether or not to animate the transition
219
- - parameter completion: A block that's called after the transition is finished. The block parameter `transitionSuccessful` is `true` if the transition to the selected view controller was completed successfully. If `false`, the transition returned to the view controller it started from.
220
- */
221
- open func scrollForwardAnimated ( _ animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
217
+ Transitions to the view controller right of the currently selected view controller in a horizontal orientation, or below the currently selected view controller in a vertical orientation. Also described as going to the next page.
218
+
219
+ - parameter animated: A Boolean whether or not to animate the transition
220
+ - parameter completion: A block that's called after the transition is finished. The block parameter `transitionSuccessful` is `true` if the transition to the selected view controller was completed successfully. If `false`, the transition returned to the view controller it started from.
221
+ */
222
+ open func scrollForward ( animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
222
223
223
224
if ( self . afterViewController != nil ) {
224
225
225
226
// Cancel current animation and move
226
227
if self . scrolling {
227
- if self . orientationIsHorizontal {
228
+ if self . isOrientationHorizontal {
228
229
self . scrollView. setContentOffset ( CGPoint ( x: self . view. bounds. width * 2 , y: 0 ) , animated: false )
229
230
} else {
230
231
self . scrollView. setContentOffset ( CGPoint ( x: 0 , y: self . view. bounds. height * 2 ) , animated: false )
231
232
}
232
-
233
+
233
234
}
234
235
235
236
self . didFinishScrollingCompletionHandler = completion
236
237
self . transitionAnimated = animated
237
- if self . orientationIsHorizontal {
238
+ if self . isOrientationHorizontal {
238
239
self . scrollView. setContentOffset ( CGPoint ( x: self . view. bounds. width * 2 , y: 0 ) , animated: animated)
239
240
} else {
240
241
self . scrollView. setContentOffset ( CGPoint ( x: 0 , y: self . view. bounds. height * 2 ) , animated: animated)
241
242
}
242
-
243
+
243
244
}
244
245
}
245
246
246
247
/**
247
- Transitions to the view controller left of the currently selected view controller in a horizontal orientation, or above the currently selected view controller in a vertical orientation. Also described as going to the previous page.
248
-
249
- - parameter animated: A Boolean whether or not to animate the transition
250
- - parameter completion: A block that's called after the transition is finished. The block parameter `transitionSuccessful` is `true` if the transition to the selected view controller was completed successfully. If `false`, the transition returned to the view controller it started from.
248
+ Transitions to the view controller left of the currently selected view controller in a horizontal orientation, or above the currently selected view controller in a vertical orientation. Also described as going to the previous page.
249
+
250
+ - parameter animated: A Boolean whether or not to animate the transition
251
+ - parameter completion: A block that's called after the transition is finished. The block parameter `transitionSuccessful` is `true` if the transition to the selected view controller was completed successfully. If `false`, the transition returned to the view controller it started from.
251
252
*/
252
- open func scrollReverseAnimated ( _ animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
253
+ open func scrollReverse ( animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
253
254
if ( self . beforeViewController != nil ) {
254
-
255
+
255
256
// Cancel current animation and move
256
257
if self . scrolling {
257
258
self . scrollView. setContentOffset ( CGPoint ( x: 0 , y: 0 ) , animated: false )
@@ -263,6 +264,17 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
263
264
}
264
265
}
265
266
267
+
268
+ @available ( * , unavailable, renamed: " scrollForward(animated:completion:) " )
269
+ open func scrollForwardAnimated( _ animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
270
+ self . scrollForward ( animated: animated, completion: completion)
271
+ }
272
+
273
+ @available ( * , unavailable, renamed: " scrollReverse(animated:completion:) " )
274
+ open func scrollReverseAnimated( _ animated: Bool , completion: ( ( _ transitionSuccessful: Bool ) -> Void ) ? ) {
275
+ self . scrollReverse ( animated: animated, completion: completion)
276
+ }
277
+
266
278
267
279
// MARK: - View Controller Overrides
268
280
@@ -286,7 +298,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
286
298
}
287
299
288
300
self . scrollView. frame = self . view. bounds
289
- if self . orientationIsHorizontal {
301
+ if self . isOrientationHorizontal {
290
302
self . scrollView. contentSize = CGSize ( width: self . view. bounds. width * 3 , height: self . view. bounds. height)
291
303
} else {
292
304
self . scrollView. contentSize = CGSize ( width: self . view. bounds. width, height: self . view. bounds. height * 3 )
@@ -319,12 +331,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
319
331
320
332
// Load new before view controller if required
321
333
if self . loadNewAdjoiningViewControllersOnFinish {
322
- self . loadBeforeViewControllerForSelectedViewController ( selectedViewController)
334
+ self . loadBeforeViewController ( for : selectedViewController)
323
335
self . loadNewAdjoiningViewControllersOnFinish = false
324
336
}
325
337
326
338
// Load new after view controller
327
- self . loadAfterViewControllerForSelectedViewController ( selectedViewController)
339
+ self . loadAfterViewController ( for : selectedViewController)
328
340
329
341
330
342
// Scrolled reverse
@@ -346,12 +358,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
346
358
347
359
// Load new after view controller if required
348
360
if self . loadNewAdjoiningViewControllersOnFinish {
349
- self . loadAfterViewControllerForSelectedViewController ( selectedViewController)
361
+ self . loadAfterViewController ( for : selectedViewController)
350
362
self . loadNewAdjoiningViewControllersOnFinish = false
351
363
}
352
364
353
365
// Load new before view controller
354
- self . loadBeforeViewControllerForSelectedViewController ( selectedViewController)
366
+ self . loadBeforeViewController ( for : selectedViewController)
355
367
356
368
// Scrolled but ended up where started
357
369
} else if ( selectedViewController == self . selectedViewController) {
@@ -383,9 +395,9 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
383
395
384
396
if self . loadNewAdjoiningViewControllersOnFinish {
385
397
if ( self . navigationDirection == . forward) {
386
- self . loadAfterViewControllerForSelectedViewController ( selectedViewController)
398
+ self . loadAfterViewController ( for : selectedViewController)
387
399
} else if ( self . navigationDirection == . reverse) {
388
- self . loadBeforeViewControllerForSelectedViewController ( selectedViewController)
400
+ self . loadBeforeViewController ( for : selectedViewController)
389
401
}
390
402
}
391
403
@@ -396,12 +408,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
396
408
397
409
}
398
410
399
- private func loadBeforeViewControllerForSelectedViewController ( _ selectedViewController: UIViewController ) {
411
+ private func loadBeforeViewController ( for selectedViewController: UIViewController ) {
400
412
// Retreive the new before controller from the data source if available, otherwise set as nil
401
413
self . beforeViewController = self . dataSource? . em_pageViewController ( self , viewControllerBeforeViewController: selectedViewController)
402
414
}
403
415
404
- private func loadAfterViewControllerForSelectedViewController ( _ selectedViewController: UIViewController ) {
416
+ private func loadAfterViewController ( for selectedViewController: UIViewController ) {
405
417
// Retreive the new after controller from the data source if available, otherwise set as nil
406
418
self . afterViewController = self . dataSource? . em_pageViewController ( self , viewControllerAfterViewController: selectedViewController)
407
419
}
@@ -430,23 +442,23 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
430
442
var afterInset : CGFloat = 0
431
443
432
444
if ( self . beforeViewController == nil ) {
433
- beforeInset = self . orientationIsHorizontal ? - viewWidth : - viewHeight
445
+ beforeInset = self . isOrientationHorizontal ? - viewWidth : - viewHeight
434
446
}
435
447
436
448
if ( self . afterViewController == nil ) {
437
- afterInset = self . orientationIsHorizontal ? - viewWidth : - viewHeight
449
+ afterInset = self . isOrientationHorizontal ? - viewWidth : - viewHeight
438
450
}
439
451
440
452
self . adjustingContentOffset = true
441
- self . scrollView. contentOffset = CGPoint ( x: self . orientationIsHorizontal ? viewWidth : 0 , y: self . orientationIsHorizontal ? 0 : viewHeight)
442
- if self . orientationIsHorizontal {
453
+ self . scrollView. contentOffset = CGPoint ( x: self . isOrientationHorizontal ? viewWidth : 0 , y: self . isOrientationHorizontal ? 0 : viewHeight)
454
+ if self . isOrientationHorizontal {
443
455
self . scrollView. contentInset = UIEdgeInsetsMake ( 0 , beforeInset, 0 , afterInset)
444
456
} else {
445
457
self . scrollView. contentInset = UIEdgeInsetsMake ( beforeInset, 0 , afterInset, 0 )
446
458
}
447
459
self . adjustingContentOffset = false
448
460
449
- if self . orientationIsHorizontal {
461
+ if self . isOrientationHorizontal {
450
462
self . beforeViewController? . view. frame = CGRect ( x: 0 , y: 0 , width: viewWidth, height: viewHeight)
451
463
self . selectedViewController? . view. frame = CGRect ( x: viewWidth, y: 0 , width: viewWidth, height: viewHeight)
452
464
self . afterViewController? . view. frame = CGRect ( x: viewWidth * 2 , y: 0 , width: viewWidth, height: viewHeight)
@@ -461,7 +473,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
461
473
462
474
// MARK: - Internal Callbacks
463
475
464
- private func willScrollFromViewController ( _ startingViewController: UIViewController ? , destinationViewController: UIViewController ) {
476
+ private func willScroll ( from startingViewController: UIViewController ? , to destinationViewController: UIViewController ) {
465
477
if ( startingViewController != nil ) {
466
478
self . delegate? . em_pageViewController ? ( self , willStartScrollingFrom: startingViewController!, destinationViewController: destinationViewController)
467
479
}
@@ -471,7 +483,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
471
483
self . addChildIfNeeded ( destinationViewController)
472
484
}
473
485
474
- private func didFinishScrollingToViewController ( _ viewController: UIViewController ) {
486
+ private func didFinishScrolling ( to viewController: UIViewController ) {
475
487
self . loadViewControllers ( viewController)
476
488
self . layoutViews ( )
477
489
}
@@ -482,20 +494,20 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
482
494
open func scrollViewDidScroll( _ scrollView: UIScrollView ) {
483
495
if !adjustingContentOffset {
484
496
485
- let distance = self . orientationIsHorizontal ? self . view. bounds. width : self . view. bounds. height
486
- let progress = ( ( self . orientationIsHorizontal ? scrollView. contentOffset. x : scrollView. contentOffset. y) - distance) / distance
497
+ let distance = self . isOrientationHorizontal ? self . view. bounds. width : self . view. bounds. height
498
+ let progress = ( ( self . isOrientationHorizontal ? scrollView. contentOffset. x : scrollView. contentOffset. y) - distance) / distance
487
499
488
500
// Scrolling forward / after
489
501
if ( progress > 0 ) {
490
502
if ( self . afterViewController != nil ) {
491
503
if !scrolling { // call willScroll once
492
- self . willScrollFromViewController ( self . selectedViewController, destinationViewController : self . afterViewController!)
504
+ self . willScroll ( from : self . selectedViewController, to : self . afterViewController!)
493
505
self . scrolling = true
494
506
}
495
507
496
508
if self . navigationDirection == . reverse { // check if direction changed
497
- self . didFinishScrollingToViewController ( self . selectedViewController!)
498
- self . willScrollFromViewController ( self . selectedViewController, destinationViewController : self . afterViewController!)
509
+ self . didFinishScrolling ( to : self . selectedViewController!)
510
+ self . willScroll ( from : self . selectedViewController, to : self . afterViewController!)
499
511
}
500
512
501
513
self . navigationDirection = . forward
@@ -509,13 +521,13 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
509
521
} else if ( progress < 0 ) {
510
522
if ( self . beforeViewController != nil ) {
511
523
if !scrolling { // call willScroll once
512
- self . willScrollFromViewController ( self . selectedViewController, destinationViewController : self . beforeViewController!)
524
+ self . willScroll ( from : self . selectedViewController, to : self . beforeViewController!)
513
525
self . scrolling = true
514
526
}
515
527
516
528
if self . navigationDirection == . forward { // check if direction changed
517
- self . didFinishScrollingToViewController ( self . selectedViewController!)
518
- self . willScrollFromViewController ( self . selectedViewController, destinationViewController : self . beforeViewController!)
529
+ self . didFinishScrolling ( to : self . selectedViewController!)
530
+ self . willScroll ( from : self . selectedViewController, to : self . beforeViewController!)
519
531
}
520
532
521
533
self . navigationDirection = . reverse
@@ -536,11 +548,11 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
536
548
537
549
// Thresholds to update view layouts call delegates
538
550
if ( progress >= 1 && self . afterViewController != nil ) {
539
- self . didFinishScrollingToViewController ( self . afterViewController!)
551
+ self . didFinishScrolling ( to : self . afterViewController!)
540
552
} else if ( progress <= - 1 && self . beforeViewController != nil ) {
541
- self . didFinishScrollingToViewController ( self . beforeViewController!)
553
+ self . didFinishScrolling ( to : self . beforeViewController!)
542
554
} else if ( progress == 0 && self . selectedViewController != nil ) {
543
- self . didFinishScrollingToViewController ( self . selectedViewController!)
555
+ self . didFinishScrolling ( to : self . selectedViewController!)
544
556
}
545
557
546
558
}
@@ -555,7 +567,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
555
567
// setContentOffset is called to center the selected view after bounces
556
568
// This prevents yucky behavior at the beginning and end of the page collection by making sure setContentOffset is called only if...
557
569
558
- if self . orientationIsHorizontal {
570
+ if self . isOrientationHorizontal {
559
571
if ( self . beforeViewController != nil && self . afterViewController != nil ) || // It isn't at the beginning or end of the page collection
560
572
( self . afterViewController != nil && self . beforeViewController == nil && scrollView. contentOffset. x > fabs ( scrollView. contentInset. left) ) || // If it's at the beginning of the collection, the decelleration can't be triggered by scrolling away from, than torwards the inset
561
573
( self . beforeViewController != nil && self . afterViewController == nil && scrollView. contentOffset. x < fabs ( scrollView. contentInset. right) ) { // Same as the last condition, but at the end of the collection
0 commit comments