可拖动的CALayer [英] Draggable CALayer

查看:61
本文介绍了可拖动的CALayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用户拖动CALayer?如果是,怎么办?

Any way of making a CALayer draggable by the user? If so, how?

(在Cocoa-Mac中)

(In Cocoa - Mac)

推荐答案

图层本身无法接收鼠标事件。您必须在包含图层的视图或视图控制器中进行事件处理。

Layers can not receive mouse events themselves. You would have to do the event handling in the view or view controller containing the layer.

如果 mouseDragged:事件起源于一层(请参见-[CALayer hitTest:] -[CALayer containsPoint:] 进行测试) ,相应地调整图层的位置。您可能要禁用隐式动画,以使图层立即跟随鼠标指针(而不是由于position属性的动画而滞后一点):

If a mouseDragged: event originates on a layer (see -[CALayer hitTest:] and -[CALayer containsPoint:] to test this), adjust the layer's position 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):

[CATransaction begin];
[CATransaction setDisableActions:YES];
layer.position = ...;
[CATransaction commit];

这篇关于可拖动的CALayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆