diff --git a/Example/Pageboy-Example/PageViewController.swift b/Example/Pageboy-Example/PageViewController.swift
index 660b54bf..6c31ce39 100644
--- a/Example/Pageboy-Example/PageViewController.swift
+++ b/Example/Pageboy-Example/PageViewController.swift
@@ -110,21 +110,24 @@ 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,
- direction: PageboyViewController.NavigationDirection) {
- self.updateBarButtonStates(index: index)
+ didScrollToPosition position: CGPoint,
+ direction: PageboyViewController.NavigationDirection,
+ animated: Bool) {
+ self.updateAppearance(pageOffset: position.x)
+ self.updateStatusLabels()
}
func pageboyViewController(_ pageboyViewController: PageboyViewController,
- didScrollToPageWithIndex index: Int,
- direction: PageboyViewController.NavigationDirection) {
+ didScrollToPageAtIndex index: Int,
+ direction: PageboyViewController.NavigationDirection,
+ animated: Bool) {
self.updateAppearance(pageOffset: CGFloat(index))
self.updateStatusLabels()
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/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
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
diff --git a/Sources/Pageboy/PageboyScrollDetection.swift b/Sources/Pageboy/PageboyScrollDetection.swift
index 07c7fda5..3471aff0 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,
@@ -85,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 ac228c5d..5071ca00 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.
///
@@ -42,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.
///
@@ -52,9 +56,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)
+ didScrollToPageAtIndex index: Int,
+ direction: PageboyViewController.NavigationDirection,
+ animated: Bool)
}
open class PageboyViewController: UIViewController {
@@ -170,7 +176,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,
@@ -178,8 +183,9 @@ open class PageboyViewController: UIViewController {
let direction = NavigationDirection.forPosition(CGFloat(currentIndex),
previous: CGFloat(oldValue ?? currentIndex))
self.delegate?.pageboyViewController(self,
- didScrollToPageWithIndex: currentIndex,
- direction: direction)
+ didScrollToPageAtIndex: currentIndex,
+ direction: direction,
+ animated: self.isScrollingAnimated)
}
}
@@ -207,6 +213,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
//
@@ -245,7 +262,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],
@@ -263,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)
diff --git a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift
index 27350aa2..1743b1ca 100644
--- a/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift
+++ b/Sources/PageboyTests/TestComponents/TestPageboyDelegate.swift
@@ -16,20 +16,23 @@ 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,
- direction: PageboyViewController.NavigationDirection) {
+ didScrollToPosition pagePosition: CGPoint,
+ direction: PageboyViewController.NavigationDirection,
+ animated: Bool) {
+ 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
}