How to simulate the slide animation of uinavigationcontroller in IOS

Source: Internet
Author: User

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.
Related Article

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.