Code Monkey home page Code Monkey logo

elastictransition-objc's Introduction

ElasticTransition ObjC Version

This is the Objective-C Version of Elastic Transition written in Swift by lkzhao https://github.com/lkzhao/ElasticTransition

A UIKit custom modal transition that simulates an elastic drag. Written in Objective-C. Feel free to contribute!

demo

Installation

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

pod "ElasticTransitionObjC"

Usage

First of all, in your view controller, create an instance of ElasticTransition

- (void)viewDidLoad {

//...

    ElasticTransition *transition = [[ElasticTransition alloc] init];

    // customization
    transition.sticky           = YES;
    transition.showShadow       = YES;
    transition.panThreshold     = 0.4;
    transition.transformType    = TRANSLATEMID;

//...

}

Use as navigation controller's delegate

Simply assign the transition to your navigation controller's delegate

    navigationController.delegate =transition

Present as modal

In prepareForSegue, assign the transition to be the transitioningDelegate of the destinationViewController. Also, dont forget to set the modalPresentationStyle to UIModalPresentationCustom

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    segue.destinationViewController.transitioningDelegate = transition;
    segue.destinationViewController.modalPresentationStyle = UIModalPresentationCustom;

}

In your modal view controller .h implement the ElasticMenuTransitionDelegate

@interface MenuViewController: UIViewController <ElasticMenuTransitionDelegate>

@end

Then in your .m file synthesize the property and provide the contentLength value

@implementation MenuViewController

@synthesize contentLength;

-(id)initWithCoder:(NSCoder *)aDecoder{

    self = [super initWithCoder:aDecoder];

    if (self) {

        self.contentLength = 320.0;

        //...
    }

    return self;
}

@end
Interactive transition for modal transition

First, construct a pan gesture recognizer

UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] init];
[panGR addTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:panGR];

Then implement your gesture handler and fo the following:

-(void)handlePan:(UIPanGestureRecognizer*)pan{

    if (pan.state == UIGestureRecognizerStateBegan){
        // Here, you can do one of two things
        // 1. show a viewcontroller directly
        UIViewController *nextViewController = // construct your VC ...
        [transition startInteractiveTransitionFromViewController:self ToViewController:nextViewController GestureRecognizer:pan];
        // 2. perform a segue
        [transition startInteractiveTransitionFromViewController:self SegueIdentifier:@"menu" GestureRecognizer:pan];
    }else{
        [transition updateInteractiveTransitionWithGestureRecognizer:pan];
    }
}
Interactive transition for dismissing the modal
  1. Implement ElasticMenuTransitionDelegate in your modal view controller and set
    self.dismissByBackgroundTouch   = YES;
    self.dismissByBackgroundDrag    = YES;
    self.dismissByForegroundDrag    = YES;
  1. Or use your own panGestureRecognizer and call dissmissInteractiveTransition in your handler
-(void)handlePan:(UIPanGestureRecognizer*)pan{
    if (pan.state == UIGestureRecognizerStateBegan){
        [transition dismissInteractiveTransitionViewController:vc GestureRecognizer:pan Completion:nil];
    }else{
        [transition updateInteractiveTransitionWithGestureRecognizer:pan];
    }
}

Authors

lkzhao, taglia3, [email protected]

License

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

elastictransition-objc's People

Stargazers

eormskim avatar Hun-i, Song avatar Yoon Joonghyun avatar

Watchers

James Cloos avatar Yoon Joonghyun avatar Gwan-ho Kim 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.