我有一个包含启用'Wants Core Animation Layer'的
NSView
的NSWindow
。该视图包含许多NSImageView
,最初使用动画定位。当运行动画时,它非常缓慢,并且丢失了大部分帧数。然而,如果禁用'Wants Core Animation Layer',则动画可以完美地运行。我需要核心动画层,但无法弄清如何使其表现得足够好。
我能做些什么来解决性能问题吗?
以下是代码:// AppDelegate
NSRect origin = ...;
NSTimeInterval d = 0.0;
for (id view in views)
{
[view performSelector:@selector(animateFrom:) withObject:origin afterDelay:d];
d += 0.05f;
}
// NSImageView+Animations
- (void)animateFrom:(NSRect)origin
{
NSRect original = self.frame;
[self setFrame:origin];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.20f];
[[self animator] setFrame:original];
[NSAnimationContext endGrouping];
}