NSAnimation 的文档说
0.0 的帧率意味着尽可能快地进行......帧率并不能保证
合理地,尽可能快的速度应该与 60 fps 相同。
使用核心动画而不是 NSAnimation
NSAnimation 并不是核心动画的一部分(它是 AppKit 的一部分)。我会建议尝试使用 Core Animation 来代替动画。
- 将 QuartzCore.framework 添加到您的项目中
- 在您的文件中导入
- 在您正在制作动画的视图上设置
- (void)setWantsLayer:(BOOL)flag
为 YES
- 切换到动画的核心动画,例如
从上面动画的持续时间来看,“隐式动画”(仅更改图层的属性)可能最适合您。但是,如果您想要更多控制权,则可以使用显式动画,如下所示:
CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"frame"];
[moveAnimation setDuration:0.25];
// There is no frame rate in Core Animation
[moveAnimation setTimingFunction:[CAMediaTimingFunction funtionWithName: kCAMediaTimingFunctionEaseInEaseOut]];
[moveAnimation setFromValue:[NSValue valueWithCGRect:yourOldFrame]]
[moveAnimation setToValue:[NSValue valueWithCGRect:yourNewFrame]];
// To do stuff when the animation finishes, become the delegate (there is no protocol)
[moveAnimation setDelegate:self];
// Core Animation only animates (not changes the value so it needs to be set as well)
[theViewYouAreAnimating setFrame:yourNewFrame];
// Add the animation to the layer that you
[[theViewYouAreAnimating layer] addAnimation:moveAnimation forKey:@"myMoveAnimation"];
然后在你实现的回调中
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)isFinished {
// Check the animation and perform whatever you want here
// if isFinished then the animation completed, otherwise it
// was cancelled.
}