On iOS transition animation

Source: Internet
Author: User

In general, we use two transition push and present

Present

/* * 1. Set proxy-(instancetype) init {self = [super init], if (self) {self.transitioningdelegate = self; self.modalpresenta Tionstyle = Uimodalpresentationcustom; } return self; } 2. Add protocol <UIViewControllerTransitioningDelegate> 3. Override protocol Method-Initialize in Protocol method-(id< uiviewcontrolleranimatedtransitioning>) Animationcontrollerforpresentedcontroller: (UIViewController *) Presented Presentingcontroller: (Uiviewcontroller *) presenting Sourcecontroller: (Uiviewcontroller *) source{  }  -(id<uiviewcontrolleranimatedtransitioning>) Animationcontrollerfordismissedcontroller: ( Uiviewcontroller *) dismissed{  } **/

2.push

When the first controller pushes a second controller,

ViewController2 *VC = [[ViewController2 alloc]init];    Self.navigationcontroller. Delegate // must write this sentence    [Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];

A second controller

@interface viewcontroller2:uiviewcontroller<uinavigationcontrollerdelegate>@end

Proxy method

-(ID<UIViewControllerAnimatedTransitioning>) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller animationcontrollerforoperation: (uinavigationcontrolleroperation) operation Fromviewcontroller: (Uiviewcontroller *) Fromvc Toviewcontroller: (Uiviewcontroller *) ToVC {}

The above is where push and present occur, and all need to return a uiviewcontrolleranimatedtransitioning

So we write a class

@interface wjtransiation_mobile:nsobject<uiviewcontrolleranimatedtransitioning>

@end

Then modify the protocol method inside

Animation time

-(Nstimeinterval) Transitionduration: (Nullable ID <UIViewControllerContextTransitioning>) Transitioncontext;

Custom transition Animations

-(void) Animatetransition: (id <UIViewControllerContextTransitioning>) Transitioncontext;

Performing transition animations

1. Get front and rear controller

Uiviewcontroller *TOVC = [Transitioncontext viewcontrollerforkey:uitransitioncontexttoviewcontrollerkey];     *FROMVC = [Transitioncontext Viewcontrollerforkey:uitransitioncontextfromviewcontrollerkey];

2. Get the Transition animation view

UIView *containerview = [Transitioncontext Containerview];

3. Add a view to the Containerview that the front and rear controller needs to animate

[Containerview Addsubview:tempview];    [Containerview AddSubview:toVC.view];

4. Perform your own animations

Demo Link: http://pan.baidu.com/s/1kTPPUMb

Tween

// adding Transiationview Properties Dynamically @interface  *Transiationview; @end
#import <objc/runtime.h>@implementation  uiviewcontroller (transiationview)  Staticchar  transiationviewkey; -(void) Settransiationview: (UIView *) transiationview {    return objc_ Setassociatedobject (self, &Transiationviewkey, Transiationview, objc_association_retain_nonatomic);} -(UIView *) transiationview {     return objc_getassociatedobject (self, &  Transiationviewkey);} @end

On iOS transition animation

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.