可拖动的CALayer
有什么方法可以让用户拖动 CALayer 吗?如果是这样,怎么办?
(在可可 - Mac 中)
Any way of making a CALayer draggable by the user? If so, how?
(In Cocoa - Mac)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图层本身无法接收鼠标事件。您必须在包含该层的视图或视图控制器中进行事件处理。
如果
mouseDragged:
事件源自图层(请参阅-[CALayer hitTest:]
和-[CALayer containsPoint:]
来测试这一点),相应地调整图层的位置
。您可能希望禁用隐式动画以使图层立即跟随鼠标指针(而不是因为位置属性的动画而稍微落后):Layers can not receive mouse events themselves. You would have to do the event handling in the view or view controller containing the layer.
If a
mouseDragged:
event originates on a layer (see-[CALayer hitTest:]
and-[CALayer containsPoint:]
to test this), adjust the layer'sposition
accordingly. You will probably want to disable implicit animations to have the layer follow the mouse pointer immediately (rather than lagging a little behind because of the animation of the position property):我尝试通过代码创建一个窗口并向其中添加 CALayer,但我不明白为什么它没有显示。
窗口链接到一个大窗口,其中有一个半透明(黑色填充)窗口,可调整大小以填充屏幕。
我已经将窗口设置为可拖动,但为什么窗口中的 CALayer 不显示?
I tried creating a window through code and adding the CALayer to it, but I don't get why it's not showing.
Window is linked to a big window, with a semi-transparent (black filled) window that is resized to fill the screen.
I've made the window draggable, but why isn't the CALayer in the window showing?