Skip to content

Extended UIPageViewController with background color tweening written in Swift

License

Notifications You must be signed in to change notification settings

adamszeremeta/TweeningUIPageViewController

Repository files navigation

TweeningUIPageViewController

Platform License

Extended UIPageViewController with background color tweening

demo

Table of contents

Features

  • animated background color tweening between controllers

Installation

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.

Usage

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
}

License

TweeningUIPageViewController is released under the MIT license.

About

Extended UIPageViewController with background color tweening written in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published