0

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?

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
user281300
  • 1,427
  • 2
  • 19
  • 31
  • The touches* methods give you a set of UITouch objects, and the coords of these touches can be found using a method (locationInView: IIRC). – C0deH4cker Jun 30 '12 at 19:53
  • yeah but if i have weird uiview shapes, there would be transparent areas. Thinking about detecting if the touched area is transparent. – user281300 Jun 30 '12 at 20:09
  • that would essentially mean i would need to declare the area for each . A bit cumbersome and too much work. – user281300 Jun 30 '12 at 20:13

2 Answers2

2

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?

Community
  • 1
  • 1
Felix
  • 35,354
  • 13
  • 96
  • 143
1

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

Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78