CATransition custom UIViewController transition animation, uiviewcontroller

Source: Internet
Author: User

CATransition custom UIViewController transition animation, uiviewcontroller
CATransition
CATransition is a subclass of CAAnimation. You can set type and subtype to implement simple transition animation.
Type:

/* Common transition types. */CA_EXTERN NSString * const kCATransitionFade    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionMoveIn    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionPush    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionReveal    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);

You can also replace @ "fade", @ "moveIn", @ "push", @ "reveal", in addition to the four types: @ "pageCurl ", @ "cube", @ "flip", and so on.
Subtype:
/* Common transition subtypes. */CA_EXTERN NSString * const kCATransitionFromRight    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionFromLeft    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionFromTop    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);CA_EXTERN NSString * const kCATransitionFromBottom    __OSX_AVAILABLE_STARTING (__MAC_10_5, __IPHONE_2_0);

You can also directly use the corresponding string: @ "fromRight", @ "fromLeft", @ "fromTop", @ "fromBottom"
Set animated to NO for the Present Type Transition animation, and add the animation to self. view. window. layer.
/*** CATransition ***///CATransition- (CATransition *)transition{    CATransition *transition = [CATransition animation];    transition.duration = 1;    transition.type = @"cube";    transition.subtype = @"fromRight";    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];    return transition;}- (void)onClick:(id)sender{    ViewController2 *vc2 = [[ViewController2 alloc] init];    [self presentViewController:vc2 animated:NO completion:nil];    [self.view.window.layer addAnimation:[self transition] forKey:@"kTransitionAnimation"];}

Set the animation to NO for the Push type transition animation, and add the animation to self. view. window. layer or self. navigationController. view. layer.
/*** CATransition ***///CATransition- (CATransition *)transition{    CATransition *transition = [CATransition animation];    transition.duration = 1;    transition.type = @"cube";    transition.subtype = @"fromRight";    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];    return transition;}- (void)onClick:(id)sender{    ViewController2 *vc2 = [[ViewController2 alloc] init];    [self.navigationController pushViewController:vc2 animated:NO];    [self.view.window.layer addAnimation:[self transition] forKey:@"kTransitionAnimation"];    // or [self.navigationController.view.layer addAnimation:[self transition] forKey:kTransitionAnimation];}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.