问题
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