IOS7 using proxy custom navigation transitions animations

Source: Internet
Author: User

If you're tired of using uinavigationcontroller for simple, rough push and pop transitions, you can use custom navigation transitions, IOS7 offers a number of nice proxy methods to help you implement a variety of custom animations, The following shows a simple navigation transition animation demo implementation process, the effect is as follows:




STEP 1: Create a project that contains a view controller named Firstviewcontroller and a Secondviewcontroller, Two popanimation and Pushanimation classes that inherit from NSObject.


STEP2: Customizing the Push animation using the Uiviewcontrolleranimatiedtransitioning proxy method

1.) Let popanimation use the Uiviewcontrolleranimatedtransitioning Proxy method:

@interface Pushanimation:nsobject <UIViewControllerAnimatedTransitioning>
2.) Implementation of Popanimation


-(void) Animatetransition: (id<uiviewcontrollercontexttransitioning>) transitioncontext {UIViewController *FR    Omviewcontroller = [Transitioncontext Viewcontrollerforkey:uitransitioncontextfromviewcontrollerkey]; Uiviewcontroller *toviewcontroller = [Transitioncontext viewcontrollerforkey:        Uitransitioncontexttoviewcontrollerkey];    [[Transitioncontext Containerview] addSubview:toViewController.view];      ToViewController.view.alpha = 0; [UIView animatewithduration:0.3*[self Transitionduration:transitioncontext] animations:^{FromViewController.view.        Transform = Cgaffinetransformmakescale (0.6, 0.6);    ToViewController.view.alpha = 0.3;   } completion:^ (BOOL finished) {[UIView animatewithduration:0.3*[self Transitionduration:transitioncontext]            animations:^{FromViewController.view.transform = Cgaffinetransformmakescale (1.1, 1.1);        ToViewController.view.alpha = 0.6;   } completion:^ (BOOL finished) {                     [UIView animatewithduration:0.4*[self Transitionduration:transitioncontext] animations:^{                FromViewController.view.transform = Cgaffinetransformmakescale (0.1, 0.1);            ToViewController.view.alpha = 1.0; } completion:^ (BOOL finished) {fromViewController.view.transform = Cgaffinetransformidentit                Y [Transitioncontext completetransition:!            [Transitioncontext transitionwascancelled]];                  }];    }]; }];}

-(Nstimeinterval) Transitionduration: (id<uiviewcontrollercontexttransitioning>) TransitionContext {    return 3.0f;}

STEP 3: Customizing pop animations using the Uiviewcontrolleranimatiedtransitioning proxy method

@interface Popanimation:nsobject <UIViewControllerAnimatedTransitioning>

-(void) Animatetransition: (id<uiviewcontrollercontexttransitioning>) Transitioncontext {UIViewController    *fromviewcontroller = [Transitioncontext Viewcontrollerforkey:uitransitioncontextfromviewcontrollerkey]; Uiviewcontroller *toviewcontroller = [Transitioncontext viewcontrollerforkey:        Uitransitioncontexttoviewcontrollerkey];        [[Transitioncontext Containerview] addSubview:toViewController.view];    ToViewController.view.alpha = 0;    ToViewController.view.transform = Cgaffinetransformmakescale (0.1, 0.1); [UIView animatewithduration:[self Transitionduration:transitioncontext] animations:^{toViewController.view.transf        ORM = Cgaffinetransformmakescale (1.0, 1.0);        ToViewController.view.alpha = 1.0f;        FromViewController.view.alpha = 0.0f;        } completion:^ (BOOL finished) {fromViewController.view.transform = cgaffinetransformidentity; [Transitioncontext completetransition:!     [Transitioncontext transitionwascancelled]];       }];} -(Nstimeinterval) Transitionduration: (id<uiviewcontrollercontexttransitioning>) TransitionContext {return 3.0f;}

STEP4: Some ways to implement Uinavigationcontrollerdelegate in Firstviewcontroller

#import "PushAnimation.h" @interface Firstviewcontroller:uiviewcontroller <uinavigationcontrollerdelegate>@ Property (Nonatomic, Strong) pushanimation *animation;

-(void) viewdidload{[Super Viewdidload];        _animation = [Pushanimation new];        Hide Navigationbar Self.navigationController.navigationBarHidden = YES;    Set background picture Uiimageview *imageview = [[Uiimageview alloc]initwithframe:self.view.frame];    [ImageView setimage:[uiimage imagenamed:@ "1.jpg"];        [Self.view Addsubview:imageview];    Define a button UIButton *pushbtn = [UIButton buttonwithtype:uibuttontyperoundedrect];    Pushbtn.frame = CGRectMake (284, 700, 200, 40);    [Pushbtn settitle:@ "push" forstate:uicontrolstatenormal];    PushBtn.titleLabel.font = [Uifont systemfontofsize:32.0f];        [Pushbtn addtarget:self Action: @selector (buttonclicked:) forcontrolevents:uicontroleventtouchupinside];    [Self.view ADDSUBVIEW:PUSHBTN];    }-(void) Viewdidappear: (BOOL) animated {[Super viewdidappear:animated]; Self.navigationController.delegate = self;}    -(void) Viewwilldisappear: (BOOL) animated {[Super viewwilldisappear:animated]; if (self.navigationcontrollEr.delegate = = self) {self.navigationController.delegate = nil;        }}-(void) buttonclicked: (ID) Sender {secondviewcontroller *presentcontroller = [[Secondviewcontroller alloc]init]; [Self.navigationcontroller Pushviewcontroller:presentcontroller animated:yes];} #pragma mask uinavigationcontrollerdelegate-(ID <UIViewControllerAnimatedTransitioning>) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Animationcontrollerf Oroperation: (uinavigationcontrolleroperation) operation Fromviewcontroller: (    Uiviewcontroller *) Fromvc Toviewcontroller: (Uiviewcontroller *) ToVC {    if (Operation = = Uinavigationcontrolleroperationpush) {return self.animation; } return nil;}

STEP5: Calling Popanimation animation in Secondviewcontroller


@interface Secondviewcontroller:uiviewcontroller <UINavigationControllerDelegate> @property (nonatomic, Strong) Popanimation *animation;

-(void) viewdidload{[Super Viewdidload];        _animation = [Popanimation new];        Hide Navigationbar Self.navigationController.navigationBarHidden = YES;    Set background picture Uiimageview *imageview = [[Uiimageview alloc]initwithframe:self.view.frame];    [ImageView setimage:[uiimage imagenamed:@ "2.jpg"];        [Self.view Addsubview:imageview];    Define a button UIButton *pushbtn = [UIButton buttonwithtype:uibuttontyperoundedrect];    Pushbtn.frame = CGRectMake (284, 700, 200, 40);    [Pushbtn settitle:@ "Pop" forstate:uicontrolstatenormal];    PushBtn.titleLabel.font = [Uifont systemfontofsize:32.0f];        [Pushbtn addtarget:self Action: @selector (buttonclicked:) forcontrolevents:uicontroleventtouchupinside];    [Self.view ADDSUBVIEW:PUSHBTN];    }-(void) Viewdidappear: (BOOL) animated {[Super viewdidappear:animated]; Self.navigationController.delegate = self;}    -(void) Viewwilldisappear: (BOOL) animated {[Super viewwilldisappear:animated]; if (Self.navigationcontroLler.delegate = = self) {self.navigationController.delegate = nil;    }}-(void) buttonclicked: (ID) Sender {[Self.navigationcontroller popviewcontrolleranimated:yes]; } #pragma mask uinavigationcontrollerdelegate-(ID <UIViewControllerAnimatedTransitioning>) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Animationcontrollerf Oroperation: (uinavigationcontrolleroperation) operation Fromviewcontroller: (    Uiviewcontroller *) Fromvc Toviewcontroller: (Uiviewcontroller *) ToVC {    if (Operation = = Uinavigationcontrolleroperationpop) {return self.animation; } return nil;}

Step6:over.


Source: http://download.csdn.net/detail/luozhonglan/7979545

*************************************************************************************************************** ************************************************************************













IOS7 using proxy custom navigation transitions animations

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.