[英]How to detect touch on screen in custom UIView?
I want to watch in my UIView
subclass for user touches on the screen. 我想在UIView
子类中查看屏幕上的用户触摸。 Especially there are some additional conditions: 特别是还有一些其他条件:
I can suppose to add specific fullscreen view with customized hitTest:
method. 我可以假设使用自定义的hitTest:
方法添加特定的全屏视图。 This view has interface to add/remove delegates for watching for touches. 该视图具有添加/删除代表以观察触摸的界面。 But this method is "hard" in coding terms and I would like to find more elegant and simpler solution. 但是这种方法在编码方面是“困难的”,我想找到更优雅,更简单的解决方案。
you can write touchesBegan in that UIView subclass. 您可以在该UIView子类中编写touchesBegan。
Because if it had any subview like button or scrollView, they would be first responders ,and touches on scrollView wont fire touchesBegan of your UIView subclass. 因为如果它具有诸如button或scrollView的任何子视图,则它们将是第一响应者,并且对scrollView的触摸不会触发UIView子类的touchesBegan。
And it wont conflict with other touch listeners unless the listener subView is explicitly passing that touch to your Subclass. 并且它不会与其他触摸侦听器发生冲突,除非侦听器subView将该触摸显式传递给您的子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.