GithubHelp home page GithubHelp logo

andy-jiangbin / yfcardtransitions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yuriferretti/yfcardtransitions

0.0 1.0 0.0 3.98 MB

Stacked card layout transitions

License: MIT License

Objective-C 99.45% Ruby 0.55%

yfcardtransitions's Introduction

YFCardTransitions

YFCardTransitions is a set of custom UIViewController transitions designed to be used with Tim Gleue's awesome TGLStackedViewController.

Installation

With CocoaPods, add this line to your Podfile.

pod 'YFCardTransitions'

Or drag the files inside the Source folder to your project

##Screenshots

Example

##Usage

First you have to subclass TGStackedViewController that conforms to UIViewControllerTransitioningDelegate and add two properties that will be responsible for the transitions:

@interface YFCardCollectionViewController () <UIViewControllerTransitioningDelegate>

@property (strong, nonatomic) YFCardPickTranstion           *cardPickTransition;
@property (strong, nonatomic) YFDragDownToDismissTransition *dragDownToDismissTransition;

@end

You have to set YFCardPickTransition duaration property to a desired value and cardTopReveal to the same value as TGLStackedLayout topReveal property

- (YFCardPickTranstion *)cardPickTransition {
    if (!_cardPickTransition) {
        _cardPickTransition = [YFCardPickTranstion new];
        _cardPickTransition.duration = 0.5;
        _cardPickTransition.cardTopReveal = self.stackedLayout.topReveal;
    }
    return _cardPickTransition;
}

Also create an UICollectionViewCell subclass to be used by you TGLStackedViewController subclass

In UICollectionViewDelegate protocol method collectionView:didSelectItemAtIndexPath: you should grab the selected cell reference frame and snapshot:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
    CGRect referenceFrame = [collectionView convertRect:attributes.frame toView:collectionView.superview];
    
    self.cardPickTransition.referenceFrame = referenceFrame;
    
    CardCollectionViewCell *cell = (CardCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    UIView *snapshotView = [cell snapshotViewAfterScreenUpdates:YES];

    self.cardPickTransition.movingCardSnapshot = snapshotView;
    
    self.selectedCardColor = cell.imageView.tintColor;
    
    [self performSegueWithIdentifier:@"showDetail" sender:nil];
    
}

Implement the UIViewControllerTransitioningDelegate methods :

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    
    return self.cardPickTransition;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return  self.dragDownToDismissTransition;
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator {
    
    return self.dragDownToDismissTransition;
}

Wire the presented view controller to the YFDragDownToDismissTransition instance :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    ViewController *vc = segue.destinationViewController;
    [self.dragDownToDismissTransition wireToViewController:vc];
    vc.transitioningDelegate = self;
    vc.modalPresentationStyle = UIModalPresentationCustom;
}

A complete working example is provided in this repository.

##Requirements

  • iOS 7 or higher
  • ARC

##Credits

##Author

##License

The MIT License

Copyright (c) 2015 Yuri Ferretti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

yfcardtransitions's People

Contributors

yuriferretti avatar

Watchers

 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.