Giter Site home page Giter Site logo

mixlan123 / ytpagecontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yeatse/ytpagecontroller

0.0 2.0 0.0 7.65 MB

Easy to make smooth transitions with `UIPageViewController`, inspired by Apple's offical Music app.

License: MIT License

Ruby 1.63% Objective-C 67.47% Swift 14.21% Shell 16.69%

ytpagecontroller's Introduction

YTPageController

Build Status Version License Platform

YTPageController introduces a neat and general solution to perform smooth transitions when scrolling between view controllers, like what Apple did in their Music app:

YTPageController can act as a drop-in replacement of UIPageViewController in your next app, and you no longer need listening to the contentOffset changes and changing the tint colors or frames your self.

Introduction

YTPageController provides a property named pageCoordinator, which is similar to transitionCoordinator in UIViewController, for you to perform your own animations during the page transtion.

For example, to animate a UISegmentedControl, you can simply add these lines your YTPageControllerDelegate:

// Called before a transition starts
- (void)pageController:(YTPageController *)pageController willStartTransition:(id<YTPageTransitionContext>)context {
    // Add your own animations using `pageCoordinator`
    [pageController.pageCoordinator animateAlongsidePagingInView:self.segmentedControl animation:^(id<YTPageTransitionContext>  _Nonnull context) {
        // Update your segmented control according to the context object.
        self.segmentedControl.userInteractionEnabled = NO;
        self.segmentedControl.selectedSegmentIndex = [context toIndex];
    } completion:^(id<YTPageTransitionContext>  _Nonnull context) {
        if ([context isCanceled]) {
            // If transition canceled, restore to the previous state
            self.segmentedControl.selectedSegmentIndex = [context fromIndex];
        }
        self.segmentedControl.userInteractionEnabled = YES;
    }];
}

YTPageController works perfectly with UIKit or third party UI controls, such as AKASegmentedControl:

BetterSegmentedControl:

or any view that can be animated:

Refer to the example project for detailed information.

Basic usage

You have two ways to quickly setup YTPageController:

In code

You can use YTPageController as a child view controller or just by subclassing it. In either way, you must provide your view controllers by setting the dataSource property:

pageController.dataSource = /* your data source object */

...or viewControllers property:

pageController.viewControllers = /* an array of child view controllers */

If you set both properties, dataSource will take the priority.

Using storyboard

You can also set up YTPageController in storyboard without any code, like what you did before with UITabBarController:

Since Apple hasn't provided a custom relationship segue, you need to follow these steps to simulate it:

  1. Drag a custom segue from YTPageController to one of your child view controllers and change its class to YTPageControllerSegue;
  2. Name the identifier of this segue with the format YTPage_{index}, such as YTPage_0, YTPage_1, YTPage_2, ...

YTPageController will find and perform all these segues in runtime to add the connected view controllers to its child view controllers.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 8.0 or above. May be working from iOS 6.0, but I haven't tested it.

Installation

YTPageController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "YTPageController"

Author

Yeatse CC, [email protected]

License

YTPageController is available under the MIT license. See the LICENSE file for more info.

ytpagecontroller's People

Contributors

yeatse avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.