本文介绍了是否可以使用Cocoa Touch手势识别器与图层/ CALayer对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用带有图层的手势识别器?让我们说,我想添加几个子图层到我的视图,实现拖放,以及点击单个元素。
是可能吗?

解决方案

您可以尝试在 UIView 然后调用

   - (CALayer *)hitTest:(CGPoint)thePoint 
在您的视图图层上找到



CALayer * layerThatWasTapped = [gestureView.layer hitTest:[gestureRecognizer locationInView:gestureView]];


Is it possible to use gesture recognizers with layers? Let's say I want to add several sublayers to my view and implement drag&drop as well as tapping on single element.Is it possible at all ? What is the best pattern?

解决方案

You could try adding gesturerecognizers to your UIView and then call

- (CALayer *)hitTest:(CGPoint)thePoint

on your view's layer to find which layer you hit, eg;

CALayer* layerThatWasTapped = [gestureView.layer hitTest:[gestureRecognizer locationInView:gestureView]];

这篇关于是否可以使用Cocoa Touch手势识别器与图层/ CALayer对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:07