通过 Cocoa 绑定在 NSView 上设置动画 setHidden:
我目前正在对一个项目进行最后的润色。
目前,许多(如果不是全部)UI 逻辑都依赖于 Cocoa Bindings。 某些用户界面元素(标签、按钮等)已定义其“隐藏”绑定。当触发某些事件时,这些元素的可见性会被切换。
我正在尝试对可见性变化进行动画处理(通过对不透明度甚至比例进行动画处理)。这可以通过多种方式轻松完成,可以通过设置相关图层属性、向图层添加动画等。但是,由于我试图完全依赖绑定行为,所以我“不能”真正做到这一点直接这个。
我尝试了使用层操作的实现,通过为相关元素上的键 kCAOnOrderIn
和 kCAOnOrderOut
定义操作,但它确实不起作用,因为 setHidden :
很可能是在NSView
而不是CALayer
上触发的——这是有道理的。
所以,我的问题是:当 Cocoa 绑定调用 setHidden:
时,如何在 NSView 上设置 setHidden:
动画。
谢谢。
I'm currently putting the final touches on a project.
A lot (if not all) of the UI logic currently relies on Cocoa Bindings.
Some of the user interface elements (labels, buttons, etc.) have their "Hidden" bindings defined. When certain events are triggered, these elements visibility is toggled.
I'm trying to animate the visibility change (by animating the opacity and maybe even the scale). This could easily be accomplished in a number of ways, either by setting the relevant layer properties, adding the animations to the layer, etc. However, since I'm trying to totally rely on the bindings behavior I "can't" really do this directly.
I tried an implementation using Layer actions, by defining actions for the keys kCAOnOrderIn
and kCAOnOrderOut
on the relevant elements, but it really didn't work, as the setHidden:
is most likely being triggered on the NSView
instead of the CALayer
-- which makes sense.
So, my question is: how would you animate setHidden:
on a NSView, when setHidden:
is being invoked by the Cocoa Bindings.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将使 NSView 淡出......
This will fade out an NSView...
对 setHidden 进行动画处理不会有任何视觉效果,因为它要么打开,要么关闭。如果您想设置可见性动画,请使用 setAlpha(或图层上的 setOpacity)。这些值介于 0.0 和 1.0 之间。如果您需要为了状态信息而设置隐藏标志,请调用
-performSelector:withObject:afterDelay
向其传递一个选择器,该选择器将隐藏值设置为您需要的任何值 动画已完成。或者,您可以设置一个委托,以便在动画完成时回调显式动画,然后调用 setHidden。Animating setHidden will have no visual effect since it's either on or off. If you want to animate visibility, use setAlpha (or setOpacity on the layer) instead. These take a value between 0.0 and 1.0. If you need the hidden flag to get set for the sake of state information, call
-performSelector:withObject:afterDelay
passing it a selector that sets the hidden value to whatever you need it to be after the animation has completed. Alternatively you can set up a delegate for explicit animation to be called back when the animation finishes and call setHidden then.我建议看看 NSViewAnimation。它需要任何 NSView 并且可以对框架、大小或可见性进行动画处理。
I would suggest taking a look at NSViewAnimation. It takes any NSView and can animate the frame, size or visibility.