iOS Development Summary (A0)-Custom View Controller Transition

Source: Internet
Author: User

How to implement custom transition

iOS 8 can be combined with uipresentation and uiviewcontrollertransitioningdelegate

No uipresentation under iOS 7 (similar to iOS 8).

The following are implemented under iOS8:

1. Set the Modalpresentationstyle property of the PRESENTEDVC to Uimodalpresentationcustom, and set the transitioningdelegate;

-Uimodalpresentationcustom tells the system that the PRESENTEDVC transition will be customized;

-Transitioningdelegate tells the system who handled the custom transition agent

-Transitioningdelegate need to implement Uiviewcontrollertransitioningdelegate protocol

2. Implementing the Transitioningdelegate Uiviewcontrollertransitioningdelegate protocol

A. Provide uipresentationcontroller (used to manage the transition process, detailed below)

B. Provide transition animations (animator (subject to Uiviewcontrolleranimatedtransitioning Protocol)) (detailed below)

// Presentation Animation -(ID <UIViewControllerAnimatedTransitioning>) Animationcontrollerforpresentedcontroller: (Uiviewcontroller *) presented Presentingcontroller: (UIViewController *) Presenting Sourcecontroller: (Uiviewcontroller *) source//  dismiss animation -(ID < uiviewcontrolleranimatedtransitioning>) Animationcontrollerfordismissedcontroller: (UIViewController *) Dismissed

3. Manage the transition process with Uipresentationcontroller

1) Override the following methods as needed to control the transition process

- (void) Presentationtransitionwillbegin;//You can add custom view to the attempt hierarchy (Containerview) in this method and animate the custom view (such as adding dimming view)//adding animations can be implemented in the following ways//-(BOOL) Animatealongsidetransition: (void (^) (id<uiviewcontrollertransitioncoordinatorcontext>context)) Animation completion: (void (^) (id<uiviewcontrollertransitioncoordinatorcontext>context)) completion;//or//-(BOOL) Animatealongsidetransitioninview: (UIView *) View animation: (void (^) (ID < Uiviewcontrollertransitioncoordinatorcontext>context)) Animation completion: (void (^) (id< Uiviewcontrollertransitioncoordinatorcontext>context)) completion;- (void) Presentationtransitiondidend: (BOOL) completed;//if completed is no, you can clear the view level- (void) Dismissaltransitionwillbegin;//animation to control custom view- (void) Dismissaltransitiondidend: (BOOL) completed;//to clean up the view hierarchy 

2) control the size of the view in the Containerview

-(CGRect) Frameofpresentedviewincontainerview// Set the size of the presneted view when the presentation is complete -( Cgsize) Sizeforchildcontentcontainer: (ID<UIContentContainer>) container Withparentcontainersize: (cgsize) parentsize//  This is the Protocol method in Uicontentcontainer (each Viewcotroller and Uipresentationcontroller comply with the agreement), return the size of the Childcontentcontainer

3) Layout

-(void) containerviewwilllayoutsubviews// can be used to control rotation, the size of each view in the Containerview

4. Provide transition animation, the main implementation of the following two methods

-(Nstimeinterval) Transitionduration: (ID <UIViewControllerContextTransitioning>) Transitioncontext; // tell the animation duration -(void) Animatetransition: (ID <UIViewControllerContextTransitioning> ) Transitioncontext; // tells how to animate, using the information provided by Transitioncontext, to change the geometry of the view involved in the animation in transition.  //  can speak [Transitioncontext Containerview] as an animated board, where you can add, remove view, and change geometry// If Present,containerview does not contain toview, you need to add it manually

iOS Development Summary (A0)-Custom View Controller Transition

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.