ios UIView 动画(onUpdate)

发布于 2025-01-02 22:33:34 字数 196 浏览 3 评论 0原文

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

整个想法是我需要一个在每一帧上运行的块动画片。我想我可以用 NSInterval 来欺骗它,但这看起来很奇怪。

想法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2025-01-09 22:33:34

请改用 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文