Search code examples
iosobjective-cswiftuiviewgesture

How to limit user interaction to an area inside UIView?


Here is a UIView, which is the yellow rectangle, and I override the drawRect: method to draw the red area, and I added the UITapGesture etc. but I just wanna to respond the red area, if the user click inside the yellow rectangle, but not on the red area, I will not respond it. Do I need to manually get the position and calculate whether it is inside the scope? Any smartier way to do so? Thanks. enter image description here


Solution

  • The only solution I know of is implementing the gestureRecognizer:shouldReceiveTouch: delegate method and verifying if your touch is inside / outside the red rectangle.