gpt4 book ai didi

objective-c - 可拖动的 CALayer

转载 作者:搜寻专家 更新时间:2023-10-30 20:04:11 24 4
gpt4 key购买 nike

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

(在 Cocoa - Mac 中)

最佳答案

图层本身不能接收鼠标事件。您必须在包含图层的 View 或 View Controller 中进行事件处理。

如果 mouseDragged: 事件起源于一个层(参见 -[CALayer hitTest:]-[CALayer containsPoint:] 来测试this), 相应地调整图层的位置。您可能希望禁用隐式动画以使图层立即跟随鼠标指针(而不是因为位置属性的动画而稍微滞后):

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

关于objective-c - 可拖动的 CALayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5127688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com