Suspend pause, resume resume for iOS animation

Source: Internet
Author: User

In the project to use the animation control, such as pause, resume and so on, first look at the code: (very easy to implement)
-(void) Pauselayer: (calayer*) layer{    cftimeinterval pausedtime = [Layer Converttime:cacurrentmediatime () Fromlayer:nil];    Layer.speed = 0.0;    Layer.timeoffset = Pausedtime;} -(void) Resumelayer: (calayer*) layer{    cftimeinterval pausedtime = [Layer Timeoffset];    Layer.speed = 1.0;    Layer.timeoffset = 0.0;    Layer.begintime = 0.0;    Cftimeinterval timesincepause = [Layer Converttime:cacurrentmediatime () Fromlayer:nil]-pausedtime;    Layer.begintime = Timesincepause;}

If in a view we have added more than one animation, (not a combination of animation), it is also easy to implement the animation pause, restore, the method is to call the above method for each animation layer layer, for example, my method is as follows, I use three individual animation combination effect, is called the following


-(void) stopanimation; {    NSLog (@ "Stop animation");    [_customview.layer removeallanimations];    [Self pauselayer:_customview1.layer];    [Self pauselayer:_customview2.layer];    [Self pauselayer:_customview3.layer];} -(void) resumeanimation{    [self resumelayer:_customview1.layer];    [Self resumelayer:_customview2.layer];    [Self resumelayer:_customview3.layer];}


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.