繁体   English   中英

ios UIView动画(onUpdate)

[英]ios UIView animation (onUpdate)

UIView animatWithDuration具有用于completion的可选参数,但我需要一个用于update

整个想法是我需要一个在动画的每个帧上运行的块。 我想我可以用NSInterval来欺骗它,但这似乎很荒谬。

有什么想法吗?

请改用CADisplayLink。 就像NSTimer一样工作,但是每帧恰好触发一次,并且将与动画完美同步。

设置方法如下:

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

您的动画代码

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

然后当动画结束时

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

暂无
暂无

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

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