Custom UIView touch area

岁酱吖の 提交于 2020-01-07 05:05:26

问题


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?


回答1:


Implement hitTest:withEvent: in your UIView subclass. Return YES only if the CGPoint is inside the shape.

Check out this question for polygon shapes: How can I determine whether a 2D Point is within a Polygon?




回答2:


Also, if you have access this talk at WWDC 2012 was pretty awesome with respect to how to handle complex touch events:

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



来源:https://stackoverflow.com/questions/11277173/custom-uiview-touch-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!