Cocoa - 两个 NSImage 之间的淡入淡出?
我有一个带有 NSImage 的菜单,显示一些信息,当它更新时,我希望新的(更新的)图像淡入。我知道这在 iPhone 上很容易,但这在 OS X 中可能吗?
I have a menu with an NSImage showing some information, and when it gets updated I would like the new (updated) image to fade in. I know it is easy on the iPhone, but is this possible in OS X ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试使用这个。它是用 Swift 4 编写的
You can try using this. It was written in Swift 4
我认为最有价值的例子之一是 ImageTransition。至少对于来自 iOS 世界的我来说,这很容易理解。
http://developer.apple.com/library/mac/samplecode/ImageTransition /ImageTransition.zip
希望有帮助,
保罗
I think that one of the most valuable example is ImageTransition. It's easy to understand at least for me, coming from the iOS world.
http://developer.apple.com/library/mac/samplecode/ImageTransition/ImageTransition.zip
Hope it helps,
Paolo
这取决于您的菜单如何显示图像。如果是菜单项本身,那么如果没有大量的黑客技术,这是不可能的。如果您在菜单中使用自定义 NSView,则可以使用两个 NSImageView 并使用视图的 -animator 在它们之间进行交换。
您可以将 imageViewB 的框架与 imageViewA 相匹配(如果尚未匹配),然后通过动画师替换子视图:
...或从 b 返回到 a。
不幸的是, NSImageView 的 -animator 代理不会对 -setImage: 进行动画处理:(没有明显的原因),因此您需要使用两个视图并对交换进行动画处理。
It depends on how your menu is showing the image. If it's the menu item itself, this isn't possible without a lot of hackery. If you're using a custom NSView in the menu, then you can use two NSImageViews and swap between them using the view's -animator.
You'd match imageViewB's frame to imageViewA if it's not already, then replace the subview through the animator:
... or back from b to a.
Unfortunately, NSImageView's -animator proxy won't animate -setImage: (for no discernible reason) so you need to use two views and animate the swap.