简体   繁体   中英

ios UIView animation (onUpdate)

UIView animatWithDuration has an optional param for completion , but I need one for update

The whole idea is I need a block that runs on EVERY frame of animation. I figure I can spoof this with a NSInterval , but that just seems hoaky.

Thoughts?

Use CADisplayLink instead. Works just like an NSTimer, but fires exactly once every frame and will be perfectly in sync with the animation.

Here's how you set one up:

self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(step)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

Your animation code

- (void)step
{
    //do something related to your animation
}

Then when the animation finishes

[self.displayLink invalidate];
self.displayLink = nil;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM