简体   繁体   English

自定义UIView触摸区域

[英]Custom UIView touch area

Hello I have some weird shapes that I need to handle the touchesBegan method on. 您好,我需要一些怪异的形状来处理touchesBegan方法。 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. 问题是UIViews是正方形的,我唯一可以做的方法是声明一个网格然后检查坐标。 Is there any other way of doing this? 还有其他方法吗?

Implement hitTest:withEvent: in your UIView subclass. 在您的UIView子类中实现hitTest:withEvent: Return YES only if the CGPoint is inside the shape. 仅当CGPoint位于形状内时返回YES。

Check out this question for polygon shapes: How can I determine whether a 2D Point is within a Polygon? 看看这个关于多边形形状的问题: 如何确定2D点是否在多边形内?

Also, if you have access this talk at WWDC 2012 was pretty awesome with respect to how to handle complex touch events: 另外,如果您可以访问WWDC 2012,那么关于如何处理复杂的触摸事件的演讲也很棒:

https://developer.apple.com/videos/wwdc/2012/?id=200 https://developer.apple.com/videos/wwdc/2012/?id=200

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

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