简体   繁体   English

如何在iOS中将触摸传递给手势识别器?

[英]How to pass touch to gesture recognizer in iOS?

I have a UIView ViewA, that we are adding to a scrollView ViewB. 我有一个UIView ViewA,我们要添加到scrollView ViewB中。 ViewA has other subviews (one of them is, ViewC). ViewA还有其他子视图(其中一个是ViewC)。 Now, we have touches methods (did begin, did end etc) on ViewA. 现在,我们在ViewA上有触摸方法(开始,结束等)。 ViewC has a tap recognizer. ViewC具有拍子识别器。 How do I pass the touch ? 我如何通过触摸?

Right now, the touches methods in ViewA are being hit. 目前,ViewA中的touchs方法正在被采用。 The gesture recognizer is not working. 手势识别器不起作用。

Can anyone kindly suggest anything ? 有人可以提出任何建议吗?

Thanks. 谢谢。 Ahsan 阿山

I would recomand you to use a UIGestureRecognizer adapted to what you want to do instead of implementing directly the touch methods. 我建议您使用适合您要执行的操作的UIGestureRecognizer,而不是直接实现touch方法。 According to Apple documentation, your are not supposed to use touch methods anymore. 根据Apple文档,您不应再使用触摸方法。

If you want to pass a gesture from one view to another one, why don't you declare a method in the .h file of your second view and call it from the first view when the gesture is triggered ? 如果要将手势从一个视图传递到另一个视图,为什么不触发第二个视图的.h文件中的方法,并在触发手势时从第一个视图调用该方法?

It's even simpler if viewB is a subview of viewA as you will have a reference of vewB in viewA. 如果viewB是viewA的子视图,则更为简单,因为您将在viewA中拥有vewB的引用。

Hope this help! 希望有帮助!

You can make one UIGestureRecognizer (A) dependant on another one (B) - so that one can't work without the second one failing. 您可以使一个UIGestureRecognizer (A)依赖于另一个UIGestureRecognizer (A)-这样,一个UIGestureRecognizer (A)不能工作而没有第二个失败。

In your case, you might add a UIGestureRecognizer (A) to the top view, and another one (B) to the view under it, that needs to recognise some other user interaction. 在您的情况下,您可能需要在顶视图中添加一个UIGestureRecognizer (A),在其下的视图中添加另一个(B),这需要识别其他用户交互。 The one (B) on the bottom view can't start working without the the other one (A) failing. 底视图(B)上的一个(B)必须在另一个(A)失败后才能开始工作。

For more UIGestureRecognizer behaviour that might suit your needs, you can read about requireGestureRecognizerToFail here and just familiarise yourself with the class that's super-useful. 有关更多可能满足您需求的UIGestureRecognizer行为,您可以在此处阅读有关requireGestureRecognizerToFail 信息 ,并使自己熟悉这个超级有用的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM