自定义UIView触摸区域 [英] Custom UIView touch area
本文介绍了自定义UIView触摸区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我需要一些奇怪的形状来处理 touchesBegan
方法.问题是 UIViews
是正方形的,我唯一能做的方法是声明一个网格,然后检查坐标.还有其他方法吗?
Hello I have some weird shapes that I need to handle the touchesBegan
method on. The issue is that UIViews
are square and the only way I could do it is to maybe declare a grid and then check the coordinates. Is there any other way of doing this?
推荐答案
在UIView子类中实现 hitTest:withEvent:
.仅当CGPoint位于形状内时才返回YES.
Implement hitTest:withEvent:
in your UIView subclass. Return YES only if the CGPoint is inside the shape.
查看此问题以获取多边形形状:如何确定2D点是否在多边形内?
Check out this question for polygon shapes: How can I determine whether a 2D Point is within a Polygon?
这篇关于自定义UIView触摸区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文