我刚刚开始使用 NSAnimation 和 Core Animation,但我似乎无法为从屏幕外滑入的 NSImage 设置动画(我也无法让旋转动画工作,但这是一个不同的问题)。当我在窗口外初始化 NSImageView (将 NSImage 设置为其图像属性)时,不会显示任何图像。我到底做错了什么导致 NSImage 不重绘?
imageView = [[NSImageView alloc] initWithFrame:NSMakeRect(-818, 0, 818, 494)];
NSImage *image = [NSImage imageNamed:@"image.png"];
[imageView setImage:image];
[mainView addSubview:imageView];
NSRect outFrame = NSMakeRect(678, 0, imageView.frame.size.width, imageView.frame.size.width);
CABasicAnimation *animation = [CABasicAnimation animation];
animation.toValue = [NSValue valueWithRect:outFrame];
NSView *view = self.window.contentView;
view.animations = @{@"frame" : animation};
[[view animator] setFrame:outFrame];