如何旋转 CALayer 支持的 NSView 子类
我有一个自定义 NSView 子类,我想使用 Core Animation 为其设置动画。我已经(没有 CA)使用 NSView 的 setFrameOrigin 和 setFrameRotation 方法设置这些视图的位置和旋转。但是,无论我做什么,一旦我向视图添加支持层,我就无法让它们旋转。
我尝试过使用 NSView 的 setFrameRotation 和 setFrameCenterRotation 方法。后者稍微移动视图,但不旋转其内容。前者没有效果。将 CATransform3DRotate 创建的 CATransform3D 应用到视图图层也没有效果。
我觉得问这个问题有点愚蠢,因为这看起来应该很容易,但对于我的生活,我不知道如何让它发挥作用。有人,请让我拍拍我的额头,这有多容易。 :)
I have a custom NSView subclass that I want to animate with Core Animation. I am already (without CA) setting the position and rotation of these views with NSView's setFrameOrigin and setFrameRotation methods. However, no matter what I do, once I add a layer backing to the views I can't get them to rotate.
I've tried using NSView's setFrameRotation and setFrameCenterRotation methods. The latter moves the view a bit, but doesn't rotate its content. The former has no effect. Applying a CATransform3D created by CATransform3DRotate to the view's layer also has no effect.
I'm feeling a little dumb asking this question, because it seems like something that should be easy, but for the life of me I can't figure out how to make it work. Someone, please make me smack my forehead at how easy it was. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,超级视图也需要分层支持才能使其发挥作用。做出这个改变就解决了这个问题。
Turns out that the superview needed to be layer-backed as well in order for this to work. Making that change fixed it.