In iOS, uinavigationcontroller adds slide animations when adding (push) and deleting (POP) views. Sometimes it is troublesome to simulate the animation by yourself.
In general, you can use catransition to use the push effect. Code As follows:
Catransition * transition = [catransition animation];
Transition. Duration = 0.3f;
Transition. timingfunction = [camediatimingfunction functionwithname: kcamediatimingfunctioneaseineaseout];
Transition. type = kcatransitionpush;
Transition. Subtype = kcatransitionfromright;
Transition. fillmode = kcafillmodebackwards;
Transition. speed = 0.5f;
Transition. removedoncompletion = yes;
[Self. View. layer removeallanimations];
[Self. View. layer addanimation: Transition forkey: Nil];
The above is the push code. During pop, you only need to change the subtype Kcatransitionfromleft .
However, when the catransition push is used, IOS will push the old view and perform fade processing. Because of this process, the screen will flash white, and it is inconsistent with the original uinavigationcontroller animation.
To solve this problem, you only need to use the brute force method. This method is to take a screenshot of the original view and generate a uiimageview, then, perform a horizontal translation animation on the uiimageview and the new view. After the animation ends, delete the new uiimageview.
Screenshot code:
Uigraphicsbeginimagecontext(Viewcontroller.View.Bounds.Size);
Calayer* Layer = viewcontroller.View.Layer;
[LayerRenderincontext:Uigraphicsgetcurrentcontext()];
Uiimage* Image =Uigraphicsgetimagefromcurrentimagecontext();
Uigraphicsendimagecontext();
Return Image;
And then use the animation of uiview to implement it,
[UiviewBeginanimations:NilContext: Nil];
[UiviewSetanimationduration:0.35f];
[ uiview setanimationdelegate : Self ];
[ uiview setanimationdidstopselector : @ selector ( animationdidstop : finished : context :];
[ uiview setanimationcurve : uiviewanimationcurveeaseinout ];
imageview. origin = cgpointmake (imageview. origin . x -screenrect. size . width , imageview. origin . Y );
Maskimageview.Origin=Cgpointmake(Maskimageview.Origin.X-Screenrect.Size.Width, Maskimageview.Origin.Y);
[ Uiview Commitanimations];
The disadvantage of this method is that it is too violent and may cause performance problems during screen capture.