From dfe3311127712273edfb47fcb0c4652ca6095026 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Wed, 22 Feb 2017 14:04:17 +0000 Subject: [PATCH 1/9] Add animated parameter to delegate methods - Add animated parameter to willScrollToPageAtIndex delegate method. - Add animated parameter to willScrollToPageWithIndex delegate method. --- Example/Pageboy-Example/PageViewController.swift | 16 +++++++++------- Sources/Pageboy/PageboyScrollDetection.swift | 4 +++- Sources/Pageboy/PageboyViewController.swift | 14 ++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Example/Pageboy-Example/PageViewController.swift b/Example/Pageboy-Example/PageViewController.swift index 660b54bf..99567279 100644 --- a/Example/Pageboy-Example/PageViewController.swift +++ b/Example/Pageboy-Example/PageViewController.swift @@ -110,21 +110,23 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource // func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPosition position: CGPoint, - direction: PageboyViewController.NavigationDirection) { - self.updateAppearance(pageOffset: position.x) - self.updateStatusLabels() + willScrollToPageAtIndex index: Int, + direction: PageboyViewController.NavigationDirection, + animated: Bool) { + self.updateBarButtonStates(index: index) } func pageboyViewController(_ pageboyViewController: PageboyViewController, - willScrollToPageAtIndex index: Int, + didScrollToPosition position: CGPoint, direction: PageboyViewController.NavigationDirection) { - self.updateBarButtonStates(index: index) + self.updateAppearance(pageOffset: position.x) + self.updateStatusLabels() } func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPageWithIndex index: Int, - direction: PageboyViewController.NavigationDirection) { + direction: PageboyViewController.NavigationDirection, + animated: Bool) { self.updateAppearance(pageOffset: CGFloat(index)) self.updateStatusLabels() diff --git a/Sources/Pageboy/PageboyScrollDetection.swift b/Sources/Pageboy/PageboyScrollDetection.swift index 07c7fda5..515ead81 100644 --- a/Sources/Pageboy/PageboyScrollDetection.swift +++ b/Sources/Pageboy/PageboyScrollDetection.swift @@ -20,7 +20,9 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg self.expectedTransitionIndex = index let direction = NavigationDirection.forPage(index, previousPage: self.currentIndex ?? index) - self.delegate?.pageboyViewController(self, willScrollToPageAtIndex: index, direction: direction) + self.delegate?.pageboyViewController(self, willScrollToPageAtIndex: index, + direction: direction, + animated: false) } public func pageViewController(_ pageViewController: UIPageViewController, diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index ac228c5d..81080586 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -32,9 +32,11 @@ public protocol PageboyViewControllerDelegate { /// - pageboyViewController: The Pageboy view controller. /// - index: The new page index. /// - direction: The direction of the scroll. + /// - animation: Whether the scroll will be animated. func pageboyViewController(_ pageboyViewController: PageboyViewController, willScrollToPageAtIndex index: Int, - direction: PageboyViewController.NavigationDirection) + direction: PageboyViewController.NavigationDirection, + animated: Bool) /// The page view controller did scroll to an offset between pages. /// @@ -52,9 +54,11 @@ public protocol PageboyViewControllerDelegate { /// - pageboyViewController: The Pageboy view controller. /// - index: The new page index. /// - direction: The direction of the scroll. + /// - animation: Whether the scroll was animated. func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPageWithIndex index: Int, - direction: PageboyViewController.NavigationDirection) + direction: PageboyViewController.NavigationDirection, + animated: Bool) } open class PageboyViewController: UIViewController { @@ -179,7 +183,8 @@ open class PageboyViewController: UIViewController { previous: CGFloat(oldValue ?? currentIndex)) self.delegate?.pageboyViewController(self, didScrollToPageWithIndex: currentIndex, - direction: direction) + direction: direction, + animated: self.isScrollingAnimated) } } @@ -245,7 +250,8 @@ open class PageboyViewController: UIViewController { let direction = NavigationDirection.forPage(rawIndex, previousPage: self.currentIndex ?? rawIndex) self.delegate?.pageboyViewController(self, willScrollToPageAtIndex: rawIndex, - direction: direction) + direction: direction, + animated: animated) self.isScrollingAnimated = true self.pageViewController.setViewControllers([viewController], From 989c2dc2f5ce6cdd0532013c55918e9e873b7607 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Wed, 22 Feb 2017 14:05:24 +0000 Subject: [PATCH 2/9] Refactor didScrollToPage delegate method Refactor didScrollToPageWithIndex to didScrollToPageAtIndex --- Example/Pageboy-Example/PageViewController.swift | 2 +- Sources/Pageboy/PageboyViewController.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/Pageboy-Example/PageViewController.swift b/Example/Pageboy-Example/PageViewController.swift index 99567279..492bbb36 100644 --- a/Example/Pageboy-Example/PageViewController.swift +++ b/Example/Pageboy-Example/PageViewController.swift @@ -124,7 +124,7 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource } func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPageWithIndex index: Int, + didScrollToPageAtIndex index: Int, direction: PageboyViewController.NavigationDirection, animated: Bool) { self.updateAppearance(pageOffset: CGFloat(index)) diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index 81080586..b6bec1ca 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -56,7 +56,7 @@ public protocol PageboyViewControllerDelegate { /// - direction: The direction of the scroll. /// - animation: Whether the scroll was animated. func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPageWithIndex index: Int, + didScrollToPageAtIndex index: Int, direction: PageboyViewController.NavigationDirection, animated: Bool) } @@ -182,7 +182,7 @@ open class PageboyViewController: UIViewController { let direction = NavigationDirection.forPosition(CGFloat(currentIndex), previous: CGFloat(oldValue ?? currentIndex)) self.delegate?.pageboyViewController(self, - didScrollToPageWithIndex: currentIndex, + didScrollToPageAtIndex: currentIndex, direction: direction, animated: self.isScrollingAnimated) } From 59308135276d52adfd4c51504c93be4c4e9e5a21 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Wed, 22 Feb 2017 14:06:10 +0000 Subject: [PATCH 3/9] Update README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4cde3c3..13005d65 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,8 @@ Called when the page view controller is about to embark on a transition to a new ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, willScrollToPageAtIndex index: Int, - direction: PageboyViewController.NavigationDirection) + direction: PageboyViewController.NavigationDirection, + animated: Bool) ``` #### didScrollToPosition @@ -82,8 +83,9 @@ Called when the page view controller did successfully complete a scroll transiti ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPageWithIndex index: Int, - direction: PageboyViewController.NavigationDirection) + didScrollToPageAtIndex index: Int, + direction: PageboyViewController.NavigationDirection, + animated: Bool) ``` ## Additional functionality From 772f855af4bff692c24dd68cdd0e9bc472f88d11 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Wed, 22 Feb 2017 15:17:27 +0000 Subject: [PATCH 4/9] Update broken test target --- .../TestComponents/TestPageboyDelegate.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift index 27350aa2..54c58968 100644 --- a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift +++ b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift @@ -16,20 +16,22 @@ class TestPageboyDelegate: PageboyViewControllerDelegate { var lastRecordedDirection: PageboyViewController.NavigationDirection? func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPosition pagePosition: CGPoint, - direction: PageboyViewController.NavigationDirection) { - lastRecordedPagePosition = pagePosition - lastRecordedDirection = direction + willScrollToPageAtIndex pageIndex: Int, + direction: PageboyViewController.NavigationDirection, + animated: Bool) { } func pageboyViewController(_ pageboyViewController: PageboyViewController, - willScrollToPageAtIndex pageIndex: Int, + didScrollToPosition pagePosition: CGPoint, direction: PageboyViewController.NavigationDirection) { + lastRecordedPagePosition = pagePosition + lastRecordedDirection = direction } func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPageWithIndex pageIndex: Int, - direction: PageboyViewController.NavigationDirection) { + didScrollToPageAtIndex pageIndex: Int, + direction: PageboyViewController.NavigationDirection, + animated: Bool) { lastRecordedPageIndex = pageIndex lastRecordedDirection = direction } From c992e46b436b2c9eec14d6289cf575d35577a75d Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Wed, 22 Feb 2017 15:22:27 +0000 Subject: [PATCH 5/9] Fix issues with orientation updates - Fix issue where PageboyViewController incorrectly observes scroll updates during orientation chages. --- Sources/Pageboy/PageboyViewController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index ac228c5d..bebb8c82 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -207,6 +207,17 @@ open class PageboyViewController: UIViewController { self.setUpPageViewController() } + open override func viewWillTransition(to size: CGSize, + with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + // ignore scroll updates during orientation change + self.pageViewController.scrollView?.delegate = nil + coordinator.animate(alongsideTransition: nil) { (context) in + self.pageViewController.scrollView?.delegate = self + } + } + // // MARK: Page management // From f0b03849b74cdaba41a4b16cc50c1fb4c6197db7 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Thu, 23 Feb 2017 09:13:32 +0000 Subject: [PATCH 6/9] Fix issue where currentIndex wouldn't update correctly --- Sources/Pageboy/PageboyViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index d90e4044..804cefff 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -174,7 +174,6 @@ open class PageboyViewController: UIViewController { public internal(set) var currentIndex: Int? { didSet { guard let currentIndex = self.currentIndex else { return } - guard currentIndex != oldValue else { return } // ensure position keeps in sync self.currentPosition = CGPoint(x: self.navigationOrientation == .horizontal ? CGFloat(currentIndex) : 0.0, From 8b5433ae194854b91f2501703fd034803f84c5a1 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Thu, 23 Feb 2017 10:22:57 +0000 Subject: [PATCH 7/9] Add animated parameter to didScrollToPosition deelgate --- Example/Pageboy-Example/PageViewController.swift | 3 ++- Sources/Pageboy/PageboyScrollDetection.swift | 6 +++++- Sources/Pageboy/PageboyViewController.swift | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Example/Pageboy-Example/PageViewController.swift b/Example/Pageboy-Example/PageViewController.swift index 492bbb36..6c31ce39 100644 --- a/Example/Pageboy-Example/PageViewController.swift +++ b/Example/Pageboy-Example/PageViewController.swift @@ -118,7 +118,8 @@ class PageViewController: PageboyViewController, PageboyViewControllerDataSource func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPosition position: CGPoint, - direction: PageboyViewController.NavigationDirection) { + direction: PageboyViewController.NavigationDirection, + animated: Bool) { self.updateAppearance(pageOffset: position.x) self.updateStatusLabels() } diff --git a/Sources/Pageboy/PageboyScrollDetection.swift b/Sources/Pageboy/PageboyScrollDetection.swift index 515ead81..3471aff0 100644 --- a/Sources/Pageboy/PageboyScrollDetection.swift +++ b/Sources/Pageboy/PageboyScrollDetection.swift @@ -87,10 +87,14 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg } else { positionPoint = CGPoint(x: scrollView.contentOffset.x, y: pagePosition) } + + // ignore duplicate updates + guard self.currentPosition != positionPoint else { return } self.currentPosition = positionPoint self.delegate?.pageboyViewController(self, didScrollToPosition: positionPoint, - direction: direction) + direction: direction, + animated: self.isScrollingAnimated) self.previousPagePosition = pagePosition } diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index 804cefff..5071ca00 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -44,9 +44,11 @@ public protocol PageboyViewControllerDelegate { /// - pageboyViewController: The Pageboy view controller. /// - position: The current relative page position. /// - direction: The direction of the scroll. + /// - animated: Whether the scroll is being animated. func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPosition position: CGPoint, - direction: PageboyViewController.NavigationDirection) + direction: PageboyViewController.NavigationDirection, + animated: Bool) /// The page view controller did complete scroll to a new page. /// @@ -279,7 +281,8 @@ open class PageboyViewController: UIViewController { if !animated { self.delegate?.pageboyViewController(self, didScrollToPosition: self.currentPosition!, - direction: direction) + direction: direction, + animated: animated) } } completion?(viewController, animated, finished) From aef84c8cc91e0ac9b3f7dddbb325858fc6b1c5fa Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Thu, 23 Feb 2017 10:36:12 +0000 Subject: [PATCH 8/9] Fix broke test delegate --- Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift index 54c58968..1743b1ca 100644 --- a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift +++ b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift @@ -23,7 +23,8 @@ class TestPageboyDelegate: PageboyViewControllerDelegate { func pageboyViewController(_ pageboyViewController: PageboyViewController, didScrollToPosition pagePosition: CGPoint, - direction: PageboyViewController.NavigationDirection) { + direction: PageboyViewController.NavigationDirection, + animated: Bool) { lastRecordedPagePosition = pagePosition lastRecordedDirection = direction } From e05b2716066eb32c622f780bc661faa049310682 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Thu, 23 Feb 2017 14:30:01 +0000 Subject: [PATCH 9/9] Update version --- Pageboy.podspec | 2 +- Sources/Pageboy/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pageboy.podspec b/Pageboy.podspec index e0913ca2..1f96e1f7 100644 --- a/Pageboy.podspec +++ b/Pageboy.podspec @@ -4,7 +4,7 @@ Pod::Spec.new do |s| s.platform = :ios, "9.0" s.requires_arc = true - s.version = "0.4.2" + s.version = "0.4.3" s.summary = "A simple, highly informative page view controller." s.description = <<-DESC Pageboy is a page view controller that provides simplified data source management, enhanced delegation and other useful features. diff --git a/Sources/Pageboy/Info.plist b/Sources/Pageboy/Info.plist index b42d31ef..caf3d926 100644 --- a/Sources/Pageboy/Info.plist +++ b/Sources/Pageboy/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.4.2 + 0.4.3 CFBundleVersion AUTO_GENERATED NSPrincipalClass