Skip to content

carabina/JTMaterialTransition

 
 

Repository files navigation

JTMaterialTransition

CI Status Version License Platform

An iOS transition for controllers based on material design.

Installation

With CocoaPods, add this line to your Podfile.

pod 'JTMaterialTransition', '~> 1.0'

Screenshots

Example

Usage

Basic usage

#import <UIKit/UIKit.h>

// You have to implement UIViewControllerTransitioningDelegate protocol
@interface ViewController : UIViewController<UIViewControllerTransitioningDelegate>
@end
#import "ViewController.h"

#import <JTMaterialTransition.h>
#import "SecondViewController.h"

@implementation ViewController

@interface ViewController ()

@property (nonatomic) JTMaterialTransition *transition;
@property (nonatomic) UIButton *presentControllerButton;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // No specific moment to call this method, just before presenting a controller
    [self createTransition];
}

- (void)didPresentControllerButtonTouch
{
    // The controller you want to present
    UIViewController *controller = [SecondViewController new];
    
    // Indicate you use a custom transition
    controller.modalPresentationStyle = UIModalPresentationCustom;
    controller.transitioningDelegate = self;

    [self presentViewController:controller animated:YES completion:nil];
}

// Initialize the tansition
- (void)createTransition
{
    // self.presentControllerButton is the animatedView used for the transition
    self.transition = [[JTMaterialTransition alloc] initWithAnimatedView:self.presentControllerButton];
}

// Indicate which transition to use when you this controller present a controller
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
    self.transition.reverse = NO;
    return self.transition;
}

// Indicate which transition to use when the presented controller is dismissed
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    self.transition.reverse = YES;
    return self.transition;
}
@end

Notes

The animatedView is not directly used, a new view is created based on the frame, backgroundColor properties for the animation. If you don't want to provide a view, you have to set startFrame and startBackgroundColor properties and call init instead of initWithAnimatedView:.

Requirements

  • iOS 7 or higher
  • Automatic Reference Counting (ARC)

Author

License

JTMaterialTransition is released under the MIT license. See the LICENSE file for more info.

About

An iOS transition for controllers based on material design.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 66.4%
  • Shell 22.0%
  • Ruby 8.7%
  • C 2.9%