如何在 NSImageView 中设置内容切换动画?
我想切换 NSImageView 中显示的图像,但我想为该更改设置动画。我尝试了各种方法来做到这一点。希望你们中的一位能够推荐一种可能真正有效的方法。我正在使用 Mac 版 Cocoa。
I want to switch the image shown in an NSImageView
, but I want to animate that change. I've tried various methods to do this. Hopefully one of you could suggest one that might actually work. I'm working with Cocoa for Mac.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知, NSImageView 不支持动画图像更改。但是,您可以将第二个 NSImageView 放置在第一个 NSImageView 之上,并以动画方式隐藏旧的并显示新的。例如:
如果您的视图很大并且可能需要 10.5+,那么您可以使用 Core Animation 做同样的事情,它将进行硬件加速并使用更少的 CPU。
创建 newImageView 后,执行以下操作:
您需要修改上面的内容才能中止,但我不会为您编写所有代码:-)
As far as I know,
NSImageView
doesn't support animating image changes. However, you can place a secondNSImageView
on top of the first one and animate hiding the old one and showing the new one. For example:If your view is big and you can require 10.5+, then you could do the same thing with Core Animation, which will be hardware accelerated and use a lot less CPU.
After creating newImageView, do something like:
You'll need to modify the above to be abortable, but I'm not going to write all your code for you :-)
您可以实现自己的自定义视图,该视图使用 Core Animation CALayer 来存储图像。当您设置图层的
contents
属性时,图像将自动平滑地从旧图像动画到新图像。You could implement your own custom view that uses a Core Animation
CALayer
to store the image. When you set thecontents
property of the layer, the image will automatically smoothly animate from the old image to the new one.