gpt4 book ai didi

objective-c - 每次运行时减少 NSTimer 间隔

转载 作者:行者123 更新时间:2023-12-03 17:32:18 26 4
gpt4 key购买 nike

我希望我的 NSTimer 每次运行时都能加快速度:

-(void)runtimer {
int delay = delay - 1;
[NSTimer scheduledTimerWithTimeInterval:(delay)
target:self
selector:@selector(timerTriggered:)
userInfo:nil
repeats:YES];

}

但这行不通。如何让延迟越来越小?

最佳答案

needed this myself并编写了一个组件 CPAccelerationTimer (Github) :

[[CPAccelerationTimer accelerationTimerWithTicks:20
totalDuration:10.0
controlPoint1:CGPointMake(0.5, 0.0) // ease in
controlPoint2:CGPointMake(1.0, 1.0)
atEachTickDo:^(NSUInteger tickIndex) {
[self timerTriggered:nil];
} completion:^{
[self timerTriggered:nil];
}]
run];

这会调用 -timerTriggered: 20 次,分布在 10 秒内,延迟不断减少(由给定的贝塞尔曲线指定)。

关于objective-c - 每次运行时减少 NSTimer 间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7896268/

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