NSView 内容的动画旋转
我正在尝试就地旋转 NSView
(NSButton
) 的内容(即从中心旋转。我想将 -
转换为<代码>|)。这可以通过 setFrameCenterRotation: 来完成...但是,我正在尝试为其设置动画,并
[[myview animator] setFrameCenterRotation: 90];
导致控件首先跳到右侧,然后绕左下角 (0,0) 旋转回到原来的位置。
有些人建议首先设置 anchorPoint
:
[[myview layer] setAnchorPoint: NSMakePoint(0.5, 0.5)];
但由于某种原因,动画取消了此设置,并将其重置为 (0, 0)。
那么,有人知道如何为 NSView
的就地旋转设置动画吗?
I'm trying to rotate the contents of an NSView
(NSButton
) in-place (I.e. from the center. I want to convert -
into |
). This can be done with setFrameCenterRotation:
… However, I'm trying to animate this, and
[[myview animator] setFrameCenterRotation: 90];
causes the control to first jump to the right, and then rotate around the bottom-left corner (0,0) back to the original location.
Some people have suggested first setting the anchorPoint
:
[[myview layer] setAnchorPoint: NSMakePoint(0.5, 0.5)];
but for some reason the animation cancels this out and it gets reset to (0, 0).
So, has anybody figured out how to animate an in-place rotation of an NSView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您从界面生成器添加控件并使用其 IBOutlet 旋转它,则不会发生这种情况。您不必使用“setAnchorPoint:”方法; “setFrameCenterRotation:”方法本身就可以工作。然而,当我尝试旋转 NSCell 中作为子视图的 NSButton 时,同样的事情发生在我身上。解决方案是将 NSView 作为 controlView 中的子视图(请参阅下面的 NSCell 子类)和 NSButton 我需要旋转作为该新 NSView 的子视图。
This doesn't happen if you add the control from interface builder and rotate it using its IBOutlet. You will not have to use "setAnchorPoint:" method; "setFrameCenterRotation:" method itself will work. However the same thing happened to me when I tried to rotate a NSButton I have in my NSCell as a subview. The solution was to have an NSView as a subview in the controlView (refer the NSCell subclass below) and NSButton I require rotation as a subview of that new NSView.