如何使用UISwipeGestureRecognizer将“点击”传递到UIView下面的UIButton? [英] How to pass a 'tap' to UIButton that is underneath UIView with UISwipeGestureRecognizer?

查看:133
本文介绍了如何使用UISwipeGestureRecognizer将“点击”传递到UIView下面的UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在(透明)UIView下面有一个UIButton。上面的UIView添加了一个UISwipeGestureRecognizer,这是它唯一的目的 - 检测某些滑动手势。我希望UIView忽略所有其他触摸,并传递给其他视图(例如我下面的UIButton)。目前,上面的UIView似乎正在检测水龙头(例如),什么也不做(应该是这样),并且不让UIButton下面有机会响应。



<如果可能的话,我宁愿不实现我自己的滑动识别器。任何解决方案/建议?我基本上只是想知道如何告诉UIView只关注某种类型的添加手势识别器,并忽略(并因此通过后面的视图)所有其他触摸。

解决方案

昨天我一定是一个恐惧 - 今天我醒来时提出了一个简单的解决方案。将UISwipeGesture添加到视图,该视图是UIView和UIButton的超视图。然后,在处理这些滑动时,找出滑动起源的位置,以及该点是否在我曾经拥有UIView的框架中。 (正如我所提到的,UIView存在的唯一原因是为这些滑动手势定义目标区域。)


I have a UIButton underneath a (transparent) UIView. The UIView above has a UISwipeGestureRecognizer added to it, and that is its only purpose - to detect certain swipe gestures. I want all other touches to be ignored by that UIView, and passed to other views (such as my UIButton underneath). Currently, the UIView above seems to be detecting the tap (for example), doing nothing (as it should be), and not letting the UIButton underneath get a chance to respond.

I would prefer not to implement my own swipe recognizer, if possible. Any solutions / advice? I basically just want to know how to tell a UIView to pay attention to only a certain type of added gesture recognizer, and ignore (and thus let through to views behind) all other touches.

解决方案

I must have just been in a funk yesterday - I woke up with a simple solution today. Add the UISwipeGesture to a view which is a superview to both the UIView and the UIButton. Then, when processing those swipes, figure out where the swipe originated, and whether that point is in the frame of where I used to have the UIView. (As I mentioned, the only reason for the existence of the UIView was to define a target area for these swipe gestures.)

这篇关于如何使用UISwipeGestureRecognizer将“点击”传递到UIView下面的UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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