From c428cfaba91d15330c1b027675637537b1e614b0 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 11:59:21 +0100 Subject: [PATCH 01/11] Add isDoubleSided to PageboyViewController --- Sources/Pageboy/PageboyViewController.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index 7285c696..a2cfb675 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -177,7 +177,13 @@ open class PageboyViewController: UIViewController { } /// default YES. if YES, bounces past edge of content and back again. public var bounces: Bool = true - + // Whether client content appears on both sides of each page. If 'NO', content on page front will partially show through back. + // If 'UIPageViewControllerSpineLocationMid' is set, 'doubleSided' is set to 'YES'. Setting 'NO' when spine location is mid results in an exception. + public var isDoubleSided: Bool = false { + didSet { + self.pageViewController?.isDoubleSided = isDoubleSided + } + } /// Whether the page view controller is currently being touched. public var isTracking: Bool { @@ -295,6 +301,8 @@ open class PageboyViewController: UIViewController { self.autoScroller.handler = self self.setUpPageViewController() + + } open override func viewWillTransition(to size: CGSize, From 846ba93ed3ccd04eb06de426a9e489e26eca82da Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:01:45 +0100 Subject: [PATCH 02/11] Refactor dataSource and delegate into separate files --- Sources/Pageboy.xcodeproj/project.pbxproj | 12 +++ Sources/Pageboy/PageboyViewController.swift | 76 ------------------- .../PageboyViewControllerDataSource.swift | 33 ++++++++ .../PageboyViewControllerDelegate.swift | 58 ++++++++++++++ 4 files changed, 103 insertions(+), 76 deletions(-) create mode 100644 Sources/Pageboy/PageboyViewControllerDataSource.swift create mode 100644 Sources/Pageboy/PageboyViewControllerDelegate.swift diff --git a/Sources/Pageboy.xcodeproj/project.pbxproj b/Sources/Pageboy.xcodeproj/project.pbxproj index 74e5301e..9a45abb0 100644 --- a/Sources/Pageboy.xcodeproj/project.pbxproj +++ b/Sources/Pageboy.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 4653DD551FC8333E00C4B758 /* PageboyViewControllerDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4653DD541FC8333E00C4B758 /* PageboyViewControllerDataSource.swift */; }; + 4653DD561FC8333E00C4B758 /* PageboyViewControllerDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4653DD541FC8333E00C4B758 /* PageboyViewControllerDataSource.swift */; }; + 4653DD581FC8335F00C4B758 /* PageboyViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4653DD571FC8335F00C4B758 /* PageboyViewControllerDelegate.swift */; }; + 4653DD591FC8335F00C4B758 /* PageboyViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4653DD571FC8335F00C4B758 /* PageboyViewControllerDelegate.swift */; }; 466A76B61FB38B32000B5C1C /* PageboyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D623B1D11E1D2DF200527F3D /* PageboyViewController.swift */; }; 466A76B71FB38B32000B5C1C /* PageboyViewController+Management.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CC557C1ECCC55F00A7FBB4 /* PageboyViewController+Management.swift */; }; 466A76B81FB38B32000B5C1C /* PageboyViewController+ScrollDetection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CC557D1ECCC55F00A7FBB4 /* PageboyViewController+ScrollDetection.swift */; }; @@ -61,6 +65,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4653DD541FC8333E00C4B758 /* PageboyViewControllerDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageboyViewControllerDataSource.swift; sourceTree = ""; }; + 4653DD571FC8335F00C4B758 /* PageboyViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageboyViewControllerDelegate.swift; sourceTree = ""; }; D623B1B71E1D0C6A00527F3D /* Pageboy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pageboy.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D623B1BA1E1D0C6A00527F3D /* Pageboy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Pageboy.h; sourceTree = ""; }; D623B1BB1E1D0C6A00527F3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -146,6 +152,8 @@ children = ( D623B1BA1E1D0C6A00527F3D /* Pageboy.h */, D623B1D11E1D2DF200527F3D /* PageboyViewController.swift */, + 4653DD571FC8335F00C4B758 /* PageboyViewControllerDelegate.swift */, + 4653DD541FC8333E00C4B758 /* PageboyViewControllerDataSource.swift */, D6CC55791ECCC54100A7FBB4 /* Extensions */, D6CC55781ECCC54100A7FBB4 /* Components */, D6ECCEC01E51AFDB00E9D5B3 /* Utilities */, @@ -423,12 +431,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4653DD551FC8333E00C4B758 /* PageboyViewControllerDataSource.swift in Sources */, D6F6F8FC1EF6DC49006397D0 /* UIViewController+PageboyExtras.swift in Sources */, D6CC557B1ECCC55300A7FBB4 /* PageboyAutoScroller.swift in Sources */, D6CC557E1ECCC55F00A7FBB4 /* PageboyViewController+Management.swift in Sources */, D67E6FDD1F1E58EE0019AB74 /* TransitionOperation.swift in Sources */, D623B1D21E1D2DF200527F3D /* PageboyViewController.swift in Sources */, D67E6FDE1F1E58EE0019AB74 /* UIView+AutoLayout.swift in Sources */, + 4653DD581FC8335F00C4B758 /* PageboyViewControllerDelegate.swift in Sources */, D67E6FDC1F1E58EE0019AB74 /* TransitionOperation+Action.swift in Sources */, D67E6FE61F1E59160019AB74 /* WeakWrapper.swift in Sources */, D67E6FE11F1E58FE0019AB74 /* UIPageViewController+ScrollView.swift in Sources */, @@ -461,12 +471,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4653DD561FC8333E00C4B758 /* PageboyViewControllerDataSource.swift in Sources */, 466A76BD1FB38B32000B5C1C /* TransitionOperation+Action.swift in Sources */, 466A76B81FB38B32000B5C1C /* PageboyViewController+ScrollDetection.swift in Sources */, 466A76BB1FB38B32000B5C1C /* UIViewController+PageboyExtras.swift in Sources */, 466A76C01FB38B32000B5C1C /* UIView+Localization.swift in Sources */, 466A76BC1FB38B32000B5C1C /* PageboyAutoScroller.swift in Sources */, 466A76B61FB38B32000B5C1C /* PageboyViewController.swift in Sources */, + 4653DD591FC8335F00C4B758 /* PageboyViewControllerDelegate.swift in Sources */, 466A76BF1FB38B32000B5C1C /* UIView+AutoLayout.swift in Sources */, 466A76C31FB38B32000B5C1C /* WeakWrapper.swift in Sources */, 466A76BA1FB38B32000B5C1C /* PageboyViewController+Extras.swift in Sources */, diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index a2cfb675..bcb655cb 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -8,81 +8,6 @@ import UIKit -public protocol PageboyViewControllerDataSource: class { - - /// The number of view controllers to display. - /// - /// - Parameter pageboyViewController: The Page view controller. - /// - Returns: The total number of view controllers to display. - func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int - - /// The view controller to display at a page index. - /// - /// - Parameters: - /// - pageboyViewController: The Page view controller. - /// - index: The page index. - /// - Returns: The view controller to display - func viewController(for pageboyViewController: PageboyViewController, - at index: PageboyViewController.PageIndex) -> UIViewController? - - /// The default page index to display in the Pageboy view controller. - /// - /// - Parameter pageboyViewController: The Pageboy view controller - /// - Returns: Default page - func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? -} - - -public protocol PageboyViewControllerDelegate: class { - - /// The page view controller will begin scrolling to a new page. - /// - /// - Parameters: - /// - pageboyViewController: The Page view controller. - /// - index: The new page index. - /// - direction: The direction of the scroll. - /// - animation: Whether the scroll will be animated. - func pageboyViewController(_ pageboyViewController: PageboyViewController, - willScrollToPageAt index: PageboyViewController.PageIndex, - direction: PageboyViewController.NavigationDirection, - animated: Bool) - - /// The page view controller did scroll to an offset between pages. - /// - /// - Parameters: - /// - pageboyViewController: The Page 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, - didScrollTo position: CGPoint, - direction: PageboyViewController.NavigationDirection, - animated: Bool) - - /// The page view controller did complete scroll to a new page. - /// - /// - Parameters: - /// - pageboyViewController: The Page view controller. - /// - index: The new page index. - /// - direction: The direction of the scroll. - /// - animation: Whether the scroll was animated. - func pageboyViewController(_ pageboyViewController: PageboyViewController, - didScrollToPageAt index: PageboyViewController.PageIndex, - direction: PageboyViewController.NavigationDirection, - animated: Bool) - - /// The page view controller did reload. - /// - /// - Parameters: - /// - pageboyViewController: The Pageboy view controller. - /// - currentViewController: The current view controller. - /// - currentPageIndex: The current page index. - func pageboyViewController(_ pageboyViewController: PageboyViewController, - didReloadWith currentViewController: UIViewController, - currentPageIndex: PageboyViewController.PageIndex) -} - - /// A simple, highly informative page view controller. open class PageboyViewController: UIViewController { @@ -119,7 +44,6 @@ open class PageboyViewController: UIViewController { case at(index: PageIndex) } - // MARK: Properties internal var pageViewController: UIPageViewController? diff --git a/Sources/Pageboy/PageboyViewControllerDataSource.swift b/Sources/Pageboy/PageboyViewControllerDataSource.swift new file mode 100644 index 00000000..94e242d8 --- /dev/null +++ b/Sources/Pageboy/PageboyViewControllerDataSource.swift @@ -0,0 +1,33 @@ +// +// PageboyViewControllerDataSource.swift +// Pageboy +// +// Created by Merrick Sapsford on 24/11/2017. +// Copyright © 2017 Merrick Sapsford. All rights reserved. +// + +import UIKit + +public protocol PageboyViewControllerDataSource: class { + + /// The number of view controllers to display. + /// + /// - Parameter pageboyViewController: The Page view controller. + /// - Returns: The total number of view controllers to display. + func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int + + /// The view controller to display at a page index. + /// + /// - Parameters: + /// - pageboyViewController: The Page view controller. + /// - index: The page index. + /// - Returns: The view controller to display + func viewController(for pageboyViewController: PageboyViewController, + at index: PageboyViewController.PageIndex) -> UIViewController? + + /// The default page index to display in the Pageboy view controller. + /// + /// - Parameter pageboyViewController: The Pageboy view controller + /// - Returns: Default page + func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? +} diff --git a/Sources/Pageboy/PageboyViewControllerDelegate.swift b/Sources/Pageboy/PageboyViewControllerDelegate.swift new file mode 100644 index 00000000..2c3c97f7 --- /dev/null +++ b/Sources/Pageboy/PageboyViewControllerDelegate.swift @@ -0,0 +1,58 @@ +// +// PageboyViewControllerDelegate.swift +// Pageboy +// +// Created by Merrick Sapsford on 24/11/2017. +// Copyright © 2017 Merrick Sapsford. All rights reserved. +// + +import UIKit + +public protocol PageboyViewControllerDelegate: class { + + /// The page view controller will begin scrolling to a new page. + /// + /// - Parameters: + /// - pageboyViewController: The Page view controller. + /// - index: The new page index. + /// - direction: The direction of the scroll. + /// - animation: Whether the scroll will be animated. + func pageboyViewController(_ pageboyViewController: PageboyViewController, + willScrollToPageAt index: PageboyViewController.PageIndex, + direction: PageboyViewController.NavigationDirection, + animated: Bool) + + /// The page view controller did scroll to an offset between pages. + /// + /// - Parameters: + /// - pageboyViewController: The Page 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, + didScrollTo position: CGPoint, + direction: PageboyViewController.NavigationDirection, + animated: Bool) + + /// The page view controller did complete scroll to a new page. + /// + /// - Parameters: + /// - pageboyViewController: The Page view controller. + /// - index: The new page index. + /// - direction: The direction of the scroll. + /// - animation: Whether the scroll was animated. + func pageboyViewController(_ pageboyViewController: PageboyViewController, + didScrollToPageAt index: PageboyViewController.PageIndex, + direction: PageboyViewController.NavigationDirection, + animated: Bool) + + /// The page view controller did reload. + /// + /// - Parameters: + /// - pageboyViewController: The Pageboy view controller. + /// - currentViewController: The current view controller. + /// - currentPageIndex: The current page index. + func pageboyViewController(_ pageboyViewController: PageboyViewController, + didReloadWith currentViewController: UIViewController, + currentPageIndex: PageboyViewController.PageIndex) +} From 09b74790d39e707f36a19415e1e13ade825796d2 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:10:59 +0100 Subject: [PATCH 03/11] Add basic support for page indicator --- .../PageboyViewController+ScrollDetection.swift | 8 ++++++++ Sources/Pageboy/PageboyViewController.swift | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift index 88755ecb..64569653 100644 --- a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift +++ b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift @@ -53,6 +53,14 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg } } + public func presentationCount(for pageViewController: UIPageViewController) -> Int { + return pageCount ?? 0 + } + + public func presentationIndex(for pageViewController: UIPageViewController) -> Int { + return targetIndex ?? 0 + } + // MARK: UIScrollViewDelegate public func scrollViewDidScroll(_ scrollView: UIScrollView) { diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index bcb655cb..ddb55d2b 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -173,9 +173,12 @@ open class PageboyViewController: UIViewController { } + /// The page index that is currently the target of a transition. This will align with currentIndex if no transition is active. + internal var targetIndex: PageIndex? /// The page index that the page view controller is currently at. public internal(set) var currentIndex: PageIndex? { didSet { + self.targetIndex = currentIndex guard let currentIndex = self.currentIndex else { return } #if os(iOS) @@ -225,8 +228,6 @@ open class PageboyViewController: UIViewController { self.autoScroller.handler = self self.setUpPageViewController() - - } open override func viewWillTransition(to size: CGSize, @@ -341,6 +342,7 @@ open class PageboyViewController: UIViewController { return } + targetIndex = toIndex isUpdatingViewControllers = true performTransition(from: fromIndex, to: toIndex, From 966f547b41b49d44e7797a972d41ba40eae7bf03 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:12:35 +0100 Subject: [PATCH 04/11] Fix transition issue with page control visible --- .../Extensions/PageboyViewController+Transitioning.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Pageboy/Extensions/PageboyViewController+Transitioning.swift b/Sources/Pageboy/Extensions/PageboyViewController+Transitioning.swift index eb3920be..496c4474 100644 --- a/Sources/Pageboy/Extensions/PageboyViewController+Transitioning.swift +++ b/Sources/Pageboy/Extensions/PageboyViewController+Transitioning.swift @@ -91,7 +91,7 @@ internal extension PageboyViewController { completion: @escaping TransitionOperation.Completion) { guard animated == true else { return } guard self.activeTransition == nil else { return } - guard let pageViewController = self.pageViewController else { return } + guard let scrollView = self.pageViewController?.scrollView else { return } prepareForTransition() @@ -113,7 +113,7 @@ internal extension PageboyViewController { self.transitionDisplayLink?.isPaused = false // start transition - self.activeTransition?.start(on: pageViewController.view.layer, + self.activeTransition?.start(on: scrollView.layer, completion: completion) } } From b5aad1d0cfeb99563f0956e053a6e46e114711b7 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:17:25 +0100 Subject: [PATCH 05/11] Add showPageIndicator to PageboyViewController --- .../PageboyViewController+ScrollDetection.swift | 6 ++++++ Sources/Pageboy/PageboyViewController.swift | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift index 64569653..588770e3 100644 --- a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift +++ b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift @@ -54,10 +54,16 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg } public func presentationCount(for pageViewController: UIPageViewController) -> Int { + guard showPageIndicator else { + return -1 + } return pageCount ?? 0 } public func presentationIndex(for pageViewController: UIPageViewController) -> Int { + guard showPageIndicator else { + return -1 + } return targetIndex ?? 0 } diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index ddb55d2b..6709adf2 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -82,7 +82,6 @@ open class PageboyViewController: UIViewController { #endif - /// The object that is the data source for the page view controller. (Defaults to self) public weak var dataSource: PageboyViewControllerDataSource? { didSet { @@ -152,7 +151,6 @@ open class PageboyViewController: UIViewController { } } - /// The transition to use when animating scrolls between pages. public var transition = Transition.defaultTransition /// The display link for transitioning. @@ -160,19 +158,16 @@ open class PageboyViewController: UIViewController { /// The active transition operation. internal var activeTransition: TransitionOperation? - /// The number of view controllers in the page view controller. internal var viewControllerCount: Int? /// A map of view controllers and related page indexes. internal var viewControllerMap = IndexedMap>() - /// The number of pages in the page view controller. public var pageCount: Int? { return viewControllerCount } - /// The page index that is currently the target of a transition. This will align with currentIndex if no transition is active. internal var targetIndex: PageIndex? /// The page index that the page view controller is currently at. @@ -220,6 +215,8 @@ open class PageboyViewController: UIViewController { /// Auto Scroller for automatic time-based page transitions. public let autoScroller = PageboyAutoScroller() + /// Whether to show the built-in UIPageViewController page indicator + public var showPageIndicator: Bool = false // MARK: Lifecycle @@ -241,7 +238,6 @@ open class PageboyViewController: UIViewController { } } - // MARK: Updating /// Scroll the page view controller to a new page. From ac16e7464c93018e8eddd76682e805cb17edec7f Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:18:31 +0100 Subject: [PATCH 06/11] Renamed showPageIndicator to showsPageControl --- Sources/Pageboy/PageboyViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Pageboy/PageboyViewController.swift b/Sources/Pageboy/PageboyViewController.swift index 6709adf2..59bbf8ba 100644 --- a/Sources/Pageboy/PageboyViewController.swift +++ b/Sources/Pageboy/PageboyViewController.swift @@ -215,8 +215,8 @@ open class PageboyViewController: UIViewController { /// Auto Scroller for automatic time-based page transitions. public let autoScroller = PageboyAutoScroller() - /// Whether to show the built-in UIPageViewController page indicator - public var showPageIndicator: Bool = false + /// Whether to show the built-in UIPageViewController page control. + public var showsPageControl: Bool = false // MARK: Lifecycle From a180ec7f2ebfa64fba5498dbb9504b34ecfebc4f Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:28:39 +0100 Subject: [PATCH 07/11] Fix compilation errors --- .../Extensions/PageboyViewController+ScrollDetection.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift index 588770e3..382313c0 100644 --- a/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift +++ b/Sources/Pageboy/Extensions/PageboyViewController+ScrollDetection.swift @@ -54,14 +54,14 @@ extension PageboyViewController: UIPageViewControllerDelegate, UIScrollViewDeleg } public func presentationCount(for pageViewController: UIPageViewController) -> Int { - guard showPageIndicator else { + guard showsPageControl else { return -1 } return pageCount ?? 0 } public func presentationIndex(for pageViewController: UIPageViewController) -> Int { - guard showPageIndicator else { + guard showsPageControl else { return -1 } return targetIndex ?? 0 From ac28fb850a5680b8f303cbf337695a0e732d409c Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:42:39 +0100 Subject: [PATCH 08/11] Remove overusage of self from example --- .../Pageboy-Example/ChildViewController.swift | 4 +-- Example/Pageboy-Example/GradientView.swift | 26 +++++++++---------- .../PageViewController+Appearance.swift | 16 ++++++------ .../Pageboy-Example/PageViewController.swift | 25 +++++++++--------- .../TransparentNavigationBar.swift | 6 ++--- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/Example/Pageboy-Example/ChildViewController.swift b/Example/Pageboy-Example/ChildViewController.swift index e96166f6..3371e563 100644 --- a/Example/Pageboy-Example/ChildViewController.swift +++ b/Example/Pageboy-Example/ChildViewController.swift @@ -23,8 +23,8 @@ class ChildViewController: UIViewController { super.viewDidLoad() if let index = self.index { - self.label.text = "Page " + String(index) - self.promptLabel.isHidden = index != 1 + label.text = "Page " + String(index) + promptLabel.isHidden = index != 1 } } } diff --git a/Example/Pageboy-Example/GradientView.swift b/Example/Pageboy-Example/GradientView.swift index 28a88236..75ee3d85 100644 --- a/Example/Pageboy-Example/GradientView.swift +++ b/Example/Pageboy-Example/GradientView.swift @@ -68,7 +68,7 @@ import UIKit animation.isRemovedOnCompletion = true animation.fillMode = kCAFillModeForwards animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) - self.gradientLayer?.add(animation, forKey: "colors") + gradientLayer?.add(animation, forKey: "colors") } } @@ -76,7 +76,7 @@ import UIKit func updateGradient() { guard let colors = self.colors else { - self.gradientLayer?.colors = [] + gradientLayer?.colors = [] return } @@ -84,32 +84,32 @@ import UIKit for color in colors { colorRefs.append(color.cgColor) } - self.gradientLayer?.colors = colorRefs + gradientLayer?.colors = colorRefs if let locations = self.locations { var locationNumbers = [NSNumber]() for location in locations { locationNumbers.append(NSNumber(value: location)) } - self.gradientLayer?.locations = locationNumbers + gradientLayer?.locations = locationNumbers } - switch self.direction { + switch direction { case .topToBottom: - self.gradientLayer?.startPoint = CGPoint(x: 0.5, y: 0.0) - self.gradientLayer?.endPoint = CGPoint(x: 0.5, y: 1.0) + gradientLayer?.startPoint = CGPoint(x: 0.5, y: 0.0) + gradientLayer?.endPoint = CGPoint(x: 0.5, y: 1.0) case .leftToRight: - self.gradientLayer?.startPoint = CGPoint(x: 0.0, y: 0.5) - self.gradientLayer?.endPoint = CGPoint(x: 1.0, y: 0.5) + gradientLayer?.startPoint = CGPoint(x: 0.0, y: 0.5) + gradientLayer?.endPoint = CGPoint(x: 1.0, y: 0.5) case .rightToLeft: - self.gradientLayer?.startPoint = CGPoint(x: 1.0, y: 0.5) - self.gradientLayer?.endPoint = CGPoint(x: 0.0, y: 0.5) + gradientLayer?.startPoint = CGPoint(x: 1.0, y: 0.5) + gradientLayer?.endPoint = CGPoint(x: 0.0, y: 0.5) case .bottomToTop: - self.gradientLayer?.startPoint = CGPoint(x: 0.5, y: 1.0) - self.gradientLayer?.endPoint = CGPoint(x: 0.5, y: 0.0) + gradientLayer?.startPoint = CGPoint(x: 0.5, y: 1.0) + gradientLayer?.endPoint = CGPoint(x: 0.5, y: 0.0) } } } diff --git a/Example/Pageboy-Example/PageViewController+Appearance.swift b/Example/Pageboy-Example/PageViewController+Appearance.swift index ca93ef14..4ba8dece 100644 --- a/Example/Pageboy-Example/PageViewController+Appearance.swift +++ b/Example/Pageboy-Example/PageViewController+Appearance.swift @@ -16,17 +16,17 @@ extension PageViewController { let previousBarButton = UIBarButtonItem(title: "Previous", style: .plain, target: self, action: #selector(previousPage(_:))) let nextBarButton = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(nextPage(_:))) - self.navigationItem.setLeftBarButton(previousBarButton, animated: false) - self.navigationItem.setRightBarButton(nextBarButton, animated: false) + navigationItem.setLeftBarButton(previousBarButton, animated: false) + navigationItem.setRightBarButton(nextBarButton, animated: false) self.previousBarButton = previousBarButton self.nextBarButton = nextBarButton - self.updateBarButtonStates(index: self.currentIndex ?? 0) + updateBarButtonStates(index: currentIndex ?? 0) } func updateBarButtonStates(index: Int) { self.previousBarButton?.isEnabled = index != 0 - self.nextBarButton?.isEnabled = index != (self.pageCount ?? 0) - 1 + self.nextBarButton?.isEnabled = index != (pageCount ?? 0) - 1 } @@ -44,8 +44,8 @@ extension PageViewController { let lowerIndex = Int(floor(pageOffset)) let upperIndex = Int(ceil(pageOffset)) - let lowerGradient = self.gradient(forIndex: lowerIndex) - let upperGradient = self.gradient(forIndex: upperIndex) + let lowerGradient = gradient(forIndex: lowerIndex) + let upperGradient = gradient(forIndex: upperIndex) if let topColor = interpolate(betweenColor: lowerGradient.topColor, and: upperGradient.topColor, @@ -59,11 +59,11 @@ extension PageViewController { } func gradient(forIndex index: Int) -> GradientConfig { - guard index >= 0 && index < self.gradients.count else { + guard index >= 0 && index < gradients.count else { return .defaultGradient } - return self.gradients[index] + return gradients[index] } func interpolate(betweenColor colorA: UIColor, diff --git a/Example/Pageboy-Example/PageViewController.swift b/Example/Pageboy-Example/PageViewController.swift index 56141423..3329d716 100644 --- a/Example/Pageboy-Example/PageViewController.swift +++ b/Example/Pageboy-Example/PageViewController.swift @@ -49,15 +49,15 @@ class PageViewController: PageboyViewController { override func viewDidLoad() { super.viewDidLoad() - self.addBarButtons() - self.view.sendSubview(toBack: self.gradientView) + addBarButtons() + view.sendSubview(toBack: gradientView) - self.dataSource = self - self.delegate = self + dataSource = self + delegate = self - self.updateGradient(for: self.currentPosition?.x ?? 0.0) - self.updateStatusLabels() - self.updateBarButtonStates(index: self.currentIndex ?? 0) + updateGradient(for: currentPosition?.x ?? 0.0) + updateStatusLabels() + updateBarButtonStates(index: currentIndex ?? 0) } func updateStatusLabels() { @@ -70,11 +70,11 @@ class PageViewController: PageboyViewController { // MARK: Actions @objc func nextPage(_ sender: UIBarButtonItem) { - self.scrollToPage(.next, animated: true) + scrollToPage(.next, animated: true) } @objc func previousPage(_ sender: UIBarButtonItem) { - self.scrollToPage(.previous, animated: true) + scrollToPage(.previous, animated: true) } } @@ -124,10 +124,9 @@ extension PageViewController: PageboyViewControllerDelegate { animated: Bool) { // print("didScrollToPageAtIndex: \(index)") - self.updateGradient(for: CGFloat(index)) - self.updateStatusLabels() - - self.updateBarButtonStates(index: index) + updateGradient(for: CGFloat(index)) + updateStatusLabels() + updateBarButtonStates(index: index) } func pageboyViewController(_ pageboyViewController: PageboyViewController, diff --git a/Example/Pageboy-Example/TransparentNavigationBar.swift b/Example/Pageboy-Example/TransparentNavigationBar.swift index d9d23bf3..7901f185 100644 --- a/Example/Pageboy-Example/TransparentNavigationBar.swift +++ b/Example/Pageboy-Example/TransparentNavigationBar.swift @@ -40,9 +40,9 @@ class TransparentNavigationBar: UINavigationBar { override func layoutSubviews() { super.layoutSubviews() - self.separatorView.frame = CGRect(x: 0.0, - y: self.bounds.size.height - 1.0, - width: self.bounds.size.width, height: 0.5) + separatorView.frame = CGRect(x: 0.0, + y: self.bounds.size.height - 1.0, + width: self.bounds.size.width, height: 0.5) } } From 5ce2f1e49faf3021485031113e6fdd0dafe671e2 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:47:10 +0100 Subject: [PATCH 09/11] Update README --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index caeefb2b..3439c8b0 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,10 @@ func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyVie ### Delegation -`UIPageViewController` doesn't provide the most useful delegate methods for detecting where you are when paging; this is where Pageboy comes in. `PageboyViewControllerDelegate` provides a number of functions for being able to detect where the page view controller is, and where it's headed. +Unfortunately, `UIPageViewController` doesn't provide the most useful delegate methods for detecting positional data. `PageboyViewControllerDelegate` provides a number of functions for being able to detect where the page view controller is, and where it's headed. #### willScrollToPageAtIndex -Called when the page view controller is about to embark on a transition to a new page. +The page view controller is about to embark on a transition to a new page. ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, @@ -96,7 +96,7 @@ func pageboyViewController(_ pageboyViewController: PageboyViewController, ``` #### didScrollToPosition -Called when the page view controller was scrolled to a relative position along the way transitioning to a new page. Also provided is the direction of the transition. +The page view controller was scrolled to a relative position along the way transitioning to a new page. Also provided is the direction of the transition. ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, @@ -106,7 +106,7 @@ func pageboyViewController(_ pageboyViewController: PageboyViewController, ``` #### didScrollToPage -Called when the page view controller did successfully complete a scroll transition to a page. +The page view controller has successfully completed a scroll transition to a page. ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, @@ -116,7 +116,7 @@ func pageboyViewController(_ pageboyViewController: PageboyViewController, ``` #### didReload -Called when the page view controller reloads its child view controllers. +The page view controller has reloaded its child view controllers. ```swift func pageboyViewController(_ pageboyViewController: PageboyViewController, @@ -143,6 +143,7 @@ func pageboyViewController(_ pageboyViewController: PageboyViewController, - `currentViewController` - The currently visible view controller if it exists. - `currentPosition` - The exact current relative position of the page view controller. - `currentIndex` - The index of the currently visible page. +- `showsPageControl` - Whether to show the built-in page control. ### Transitioning Pageboy also provides custom animated transition support. This can be customised via the `.transition` property on `PageboyViewController`. From bc8c354adce4bf90fa0a7a6f5fc3a05b721cedd6 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:51:22 +0100 Subject: [PATCH 10/11] Bump version number 2.1.0 --- Pageboy.podspec | 2 +- Sources/Pageboy/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pageboy.podspec b/Pageboy.podspec index 1cf60de8..693e5733 100644 --- a/Pageboy.podspec +++ b/Pageboy.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.requires_arc = true - s.version = "2.0.4" + s.version = "2.1.0" s.summary = "A simple, highly informative page view controller." s.description = <<-DESC 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 5baf5d16..f69838d4 100644 --- a/Sources/Pageboy/Info.plist +++ b/Sources/Pageboy/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.4 + 2.1.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass From fdfcabf6873ec6ae203587ec5d80a57ced6b0002 Mon Sep 17 00:00:00 2001 From: Merrick Sapsford Date: Fri, 24 Nov 2017 12:54:22 +0100 Subject: [PATCH 11/11] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 464277be..ee42a376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. `Pageboy` adheres to [Semantic Versioning](http://semver.org/). #### 2.x Releases +- `2.1.x` Releases - [2.1.0](#210) - `2.0.x` Releases - [2.0.0](#200) | [2.0.1](#201) | [2.0.2](#202) | [2.0.3](#203) | [2.0.4](#204) #### 1.x Releases @@ -17,6 +18,17 @@ All notable changes to this project will be documented in this file. --- +## [2.1.0](https://github.com/uias/Pageboy/releases/tag/2.1.0) +Released on 2017-11-24 + +#### Added +- [#116](https://github.com/uias/Pageboy/issues/116) Support for built-in `UIPageViewController` page control. + - by [msaps](https://github.com/msaps). +- [#116](https://github.com/uias/Pageboy/issues/116) `showsPageControl` to `PageboyViewController`. + - by [msaps](https://github.com/msaps). + +--- + ## [2.0.4](https://github.com/uias/Pageboy/releases/tag/2.0.4) Released on 2017-11-11