Skip to content

Commit bf5826c

Browse files
author
Erik Malyak
committed
Updated style to Swift 3 conventions
1 parent 5833510 commit bf5826c

File tree

6 files changed

+93
-93
lines changed

6 files changed

+93
-93
lines changed

EMPageViewController/EMPageViewController.swift

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
135135
/// The direction scrolling navigation occurs
136136
open private(set) var navigationOrientation: EMPageViewControllerNavigationOrientation = .horizontal
137137

138-
private var orientationIsHorizontal: Bool {
138+
private var isOrientationHorizontal: Bool {
139139
return self.navigationOrientation == .horizontal
140140
}
141141

@@ -147,8 +147,8 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
147147
scrollView.scrollsToTop = false
148148
scrollView.autoresizingMask = [.flexibleTopMargin, .flexibleRightMargin, .flexibleBottomMargin, .flexibleLeftMargin]
149149
scrollView.bounces = true
150-
scrollView.alwaysBounceHorizontal = self.orientationIsHorizontal
151-
scrollView.alwaysBounceVertical = !self.orientationIsHorizontal
150+
scrollView.alwaysBounceHorizontal = self.isOrientationHorizontal
151+
scrollView.alwaysBounceVertical = !self.isOrientationHorizontal
152152
scrollView.translatesAutoresizingMaskIntoConstraints = true
153153
scrollView.showsHorizontalScrollIndicator = false
154154
scrollView.showsVerticalScrollIndicator = false
@@ -202,56 +202,57 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
202202
self.afterViewController = viewController
203203
self.layoutViews()
204204
self.loadNewAdjoiningViewControllersOnFinish = true
205-
self.scrollForwardAnimated(animated, completion: completion)
205+
self.scrollForward(animated: animated, completion: completion)
206206
} else if (direction == .reverse) {
207207
self.beforeViewController = viewController
208208
self.layoutViews()
209209
self.loadNewAdjoiningViewControllersOnFinish = true
210-
self.scrollReverseAnimated(animated, completion: completion)
210+
self.scrollReverse(animated: animated, completion: completion)
211211
}
212212

213213
}
214214

215+
215216
/**
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)?) {
222223

223224
if (self.afterViewController != nil) {
224225

225226
// Cancel current animation and move
226227
if self.scrolling {
227-
if self.orientationIsHorizontal {
228+
if self.isOrientationHorizontal {
228229
self.scrollView.setContentOffset(CGPoint(x: self.view.bounds.width * 2, y: 0), animated: false)
229230
} else {
230231
self.scrollView.setContentOffset(CGPoint(x: 0, y: self.view.bounds.height * 2), animated: false)
231232
}
232-
233+
233234
}
234235

235236
self.didFinishScrollingCompletionHandler = completion
236237
self.transitionAnimated = animated
237-
if self.orientationIsHorizontal {
238+
if self.isOrientationHorizontal {
238239
self.scrollView.setContentOffset(CGPoint(x: self.view.bounds.width * 2, y: 0), animated: animated)
239240
} else {
240241
self.scrollView.setContentOffset(CGPoint(x: 0, y: self.view.bounds.height * 2), animated: animated)
241242
}
242-
243+
243244
}
244245
}
245246

246247
/**
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.
251252
*/
252-
open func scrollReverseAnimated(_ animated: Bool, completion: ((_ transitionSuccessful: Bool) -> Void)?) {
253+
open func scrollReverse(animated: Bool, completion: ((_ transitionSuccessful: Bool) -> Void)?) {
253254
if (self.beforeViewController != nil) {
254-
255+
255256
// Cancel current animation and move
256257
if self.scrolling {
257258
self.scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
@@ -263,6 +264,17 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
263264
}
264265
}
265266

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+
266278

267279
// MARK: - View Controller Overrides
268280

@@ -286,7 +298,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
286298
}
287299

288300
self.scrollView.frame = self.view.bounds
289-
if self.orientationIsHorizontal {
301+
if self.isOrientationHorizontal {
290302
self.scrollView.contentSize = CGSize(width: self.view.bounds.width * 3, height: self.view.bounds.height)
291303
} else {
292304
self.scrollView.contentSize = CGSize(width: self.view.bounds.width, height: self.view.bounds.height * 3)
@@ -319,12 +331,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
319331

320332
// Load new before view controller if required
321333
if self.loadNewAdjoiningViewControllersOnFinish {
322-
self.loadBeforeViewControllerForSelectedViewController(selectedViewController)
334+
self.loadBeforeViewController(for: selectedViewController)
323335
self.loadNewAdjoiningViewControllersOnFinish = false
324336
}
325337

326338
// Load new after view controller
327-
self.loadAfterViewControllerForSelectedViewController(selectedViewController)
339+
self.loadAfterViewController(for: selectedViewController)
328340

329341

330342
// Scrolled reverse
@@ -346,12 +358,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
346358

347359
// Load new after view controller if required
348360
if self.loadNewAdjoiningViewControllersOnFinish {
349-
self.loadAfterViewControllerForSelectedViewController(selectedViewController)
361+
self.loadAfterViewController(for: selectedViewController)
350362
self.loadNewAdjoiningViewControllersOnFinish = false
351363
}
352364

353365
// Load new before view controller
354-
self.loadBeforeViewControllerForSelectedViewController(selectedViewController)
366+
self.loadBeforeViewController(for: selectedViewController)
355367

356368
// Scrolled but ended up where started
357369
} else if (selectedViewController == self.selectedViewController) {
@@ -383,9 +395,9 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
383395

384396
if self.loadNewAdjoiningViewControllersOnFinish {
385397
if (self.navigationDirection == .forward) {
386-
self.loadAfterViewControllerForSelectedViewController(selectedViewController)
398+
self.loadAfterViewController(for: selectedViewController)
387399
} else if (self.navigationDirection == .reverse) {
388-
self.loadBeforeViewControllerForSelectedViewController(selectedViewController)
400+
self.loadBeforeViewController(for: selectedViewController)
389401
}
390402
}
391403

@@ -396,12 +408,12 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
396408

397409
}
398410

399-
private func loadBeforeViewControllerForSelectedViewController(_ selectedViewController:UIViewController) {
411+
private func loadBeforeViewController(for selectedViewController:UIViewController) {
400412
// Retreive the new before controller from the data source if available, otherwise set as nil
401413
self.beforeViewController = self.dataSource?.em_pageViewController(self, viewControllerBeforeViewController: selectedViewController)
402414
}
403415

404-
private func loadAfterViewControllerForSelectedViewController(_ selectedViewController:UIViewController) {
416+
private func loadAfterViewController(for selectedViewController:UIViewController) {
405417
// Retreive the new after controller from the data source if available, otherwise set as nil
406418
self.afterViewController = self.dataSource?.em_pageViewController(self, viewControllerAfterViewController: selectedViewController)
407419
}
@@ -430,23 +442,23 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
430442
var afterInset:CGFloat = 0
431443

432444
if (self.beforeViewController == nil) {
433-
beforeInset = self.orientationIsHorizontal ? -viewWidth : -viewHeight
445+
beforeInset = self.isOrientationHorizontal ? -viewWidth : -viewHeight
434446
}
435447

436448
if (self.afterViewController == nil) {
437-
afterInset = self.orientationIsHorizontal ? -viewWidth : -viewHeight
449+
afterInset = self.isOrientationHorizontal ? -viewWidth : -viewHeight
438450
}
439451

440452
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 {
443455
self.scrollView.contentInset = UIEdgeInsetsMake(0, beforeInset, 0, afterInset)
444456
} else {
445457
self.scrollView.contentInset = UIEdgeInsetsMake(beforeInset, 0, afterInset, 0)
446458
}
447459
self.adjustingContentOffset = false
448460

449-
if self.orientationIsHorizontal {
461+
if self.isOrientationHorizontal {
450462
self.beforeViewController?.view.frame = CGRect(x: 0, y: 0, width: viewWidth, height: viewHeight)
451463
self.selectedViewController?.view.frame = CGRect(x: viewWidth, y: 0, width: viewWidth, height: viewHeight)
452464
self.afterViewController?.view.frame = CGRect(x: viewWidth * 2, y: 0, width: viewWidth, height: viewHeight)
@@ -461,7 +473,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
461473

462474
// MARK: - Internal Callbacks
463475

464-
private func willScrollFromViewController(_ startingViewController: UIViewController?, destinationViewController: UIViewController) {
476+
private func willScroll(from startingViewController: UIViewController?, to destinationViewController: UIViewController) {
465477
if (startingViewController != nil) {
466478
self.delegate?.em_pageViewController?(self, willStartScrollingFrom: startingViewController!, destinationViewController: destinationViewController)
467479
}
@@ -471,7 +483,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
471483
self.addChildIfNeeded(destinationViewController)
472484
}
473485

474-
private func didFinishScrollingToViewController(_ viewController: UIViewController) {
486+
private func didFinishScrolling(to viewController: UIViewController) {
475487
self.loadViewControllers(viewController)
476488
self.layoutViews()
477489
}
@@ -482,20 +494,20 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
482494
open func scrollViewDidScroll(_ scrollView: UIScrollView) {
483495
if !adjustingContentOffset {
484496

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
487499

488500
// Scrolling forward / after
489501
if (progress > 0) {
490502
if (self.afterViewController != nil) {
491503
if !scrolling { // call willScroll once
492-
self.willScrollFromViewController(self.selectedViewController, destinationViewController: self.afterViewController!)
504+
self.willScroll(from: self.selectedViewController, to: self.afterViewController!)
493505
self.scrolling = true
494506
}
495507

496508
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!)
499511
}
500512

501513
self.navigationDirection = .forward
@@ -509,13 +521,13 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
509521
} else if (progress < 0) {
510522
if (self.beforeViewController != nil) {
511523
if !scrolling { // call willScroll once
512-
self.willScrollFromViewController(self.selectedViewController, destinationViewController: self.beforeViewController!)
524+
self.willScroll(from: self.selectedViewController, to: self.beforeViewController!)
513525
self.scrolling = true
514526
}
515527

516528
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!)
519531
}
520532

521533
self.navigationDirection = .reverse
@@ -536,11 +548,11 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
536548

537549
// Thresholds to update view layouts call delegates
538550
if (progress >= 1 && self.afterViewController != nil) {
539-
self.didFinishScrollingToViewController(self.afterViewController!)
551+
self.didFinishScrolling(to: self.afterViewController!)
540552
} else if (progress <= -1 && self.beforeViewController != nil) {
541-
self.didFinishScrollingToViewController(self.beforeViewController!)
553+
self.didFinishScrolling(to: self.beforeViewController!)
542554
} else if (progress == 0 && self.selectedViewController != nil) {
543-
self.didFinishScrollingToViewController(self.selectedViewController!)
555+
self.didFinishScrolling(to: self.selectedViewController!)
544556
}
545557

546558
}
@@ -555,7 +567,7 @@ open class EMPageViewController: UIViewController, UIScrollViewDelegate {
555567
// setContentOffset is called to center the selected view after bounces
556568
// This prevents yucky behavior at the beginning and end of the page collection by making sure setContentOffset is called only if...
557569

558-
if self.orientationIsHorizontal {
570+
if self.isOrientationHorizontal {
559571
if (self.beforeViewController != nil && self.afterViewController != nil) || // It isn't at the beginning or end of the page collection
560572
(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
561573
(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

EMPageViewController/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0</string>
18+
<string>3.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)