Extended UIPageViewController with background color tweening
- animated background color tweening between controllers
The prefered way is to use CococaPods.
use_frameworks!
pod 'TweeningUIPageViewController', '~> 1.0.0'
If you can't use CocoaPods for some reason, then grab the files in TweeningUIPageViewController/
and put it in your project.
Add or replace existing implementation from UIPageViewController to TweeningPageViewController
and implement TweeningPageViewControllerDelegate
protocol.
Below you can find some code snippets. You can also checkout full example project.
Set TweeningPageViewControllerDelegate
:
let pageController = ... (reference to your TweeningPageViewController instance)
pageController.tweeningDelegate = self
Implement TweeningPageViewControllerDelegate
required methods:
// MARK: TweeningUIPageViewControllerDelegate
func tweeningPageViewController(tweeningController:TweeningPageViewController, backgroundColorForControllerBeforeController viewController:UIViewController?) -> UIColor? {
if let pageController = viewController as? MyPageViewController {
let previousIndex = pageController.controllerIndex - 1
if previousIndex >= 0 && previousIndex < self.backgroundColors.count {
return self.backgroundColors[previousIndex]
}
}
return nil
}
func tweeningPageViewController(tweeningController:TweeningPageViewController, backgroundColorForCurrentController viewController:UIViewController?) -> UIColor? {
if let pageController = viewController as? MyPageViewController {
return self.backgroundColors[pageController.controllerIndex]
}
return nil
}
func tweeningPageViewController(tweeningController:TweeningPageViewController, backgroundColorForControllerAfterController viewController:UIViewController?) -> UIColor? {
if let pageController = viewController as? MyPageViewController {
let nextIndex = pageController.controllerIndex + 1
if nextIndex >= 0 && nextIndex < self.backgroundColors.count {
return self.backgroundColors[nextIndex]
}
}
return nil
}
TweeningUIPageViewController
is released under the MIT license.