CALayer 上的触摸手势
我正在 CALayer 上进行一些绘图,希望能够让用户单击绘图的不同部分并触发响应。我尝试研究手势识别器,似乎它们需要绑定到 UIView。知道如何使用 CALayers 获得我想要的行为吗?
I am doing some drawing on a CALayer and want to be able to have the user single tap different parts of the drawing and trigger a response. I tried looking into gesture recognizers, and it seems that they need to be tied to a UIView. Any idea how I can get my desired behavior using CALayers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个响应器才能响应触摸。从托管该层的视图(在树中的某个时刻,这需要为真),您可以使用
-[CALayer hitTest:]
尝试找到将响应您的最深的子层。You need a responder to be able to respond to touches. From the view that is hosting this layer (at some point in your tree this needs to be true) you can use
-[CALayer hitTest:]
to try to find the deepest sublayer that will respond to you.