简体   繁体   English

ios UIView动画(onUpdate)

[英]ios UIView animation (onUpdate)

UIView animatWithDuration has an optional param for completion , but I need one for update UIView animatWithDuration具有用于completion的可选参数,但我需要一个用于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. 我想我可以用NSInterval来欺骗它,但这似乎很荒谬。

Thoughts? 有什么想法吗?

Use CADisplayLink instead. 请改用CADisplayLink。 Works just like an NSTimer, but fires exactly once every frame and will be perfectly in sync with the animation. 就像NSTimer一样工作,但是每帧恰好触发一次,并且将与动画完美同步。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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