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