gpt4 book ai didi

ios - 非动画 UI 元素的手动动画

转载 作者:行者123 更新时间:2023-11-28 22:16:05 25 4
gpt4 key购买 nike

我想为 animateWithDuration:animations: 不支持的 UI 元素设置动画,并且不能通过转换设置动画。

首先想到的是做这样的事情:

_animationStartDate = [NSDate date];
[self performSelector:@selector(manualAnimation) withObject:nil afterDelay:1.0/MYManualAnimationFrameRate];

- (void)manualAnimation
{
NSDate *now = [NSDate date];
NSTimeInterval interval = [now timeIntervalSinceDate:_animationStartDate];
CGFloat progress = interval / MYManualAnimationDuration;
if (progress < 1)
{
[self setValuesOfManualAnimationAtProgress:progress];
[self performSelector:@selector(manualAnimation:) withObject:number afterDelay:1.0/MYManualAnimationFrameRate];
} else {
[self setValuesOfManualAnimationAtProgress:1];
}
}

在重新发明轮子之前,这些动画有没有API?

如果不是,还有什么我应该考虑的(例如,在 dealloc 中调用 cancelPreviousPerformRequestsWithTarget:selector:object:,动态帧率)?使用 GCD 我会有所收获吗?

最佳答案

Before reinventing the wheel, is there any API for these kinds of animations?

那就是 CADisplayLink它“是一个计时器对象,允许您的应用程序将其绘图同步到显示器的刷新率”

每当需要重绘时,您都可以使用它来调用具有此签名的选择器

- (void) selector:(CADisplayLink *)sender;

在您的绘图代码中,您可以使用显示链接的时间戳 来了解动画要绘制多远。

关于ios - 非动画 UI 元素的手动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21636766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com