Reputation: 2088
I have a UIView that I am rendering a UIBezierPath in based on touchesBegan and touchesMoved. But I only want to draw in a certain area within the UIVIew. I would like to set up a CGRect within the UIView where touches are only registered. Any touches outside of this area will not be registered.
Ideally if the user drages outside of this rectangle, they can keep holding the touch, but the touchesBegan method will be called when they drag back into the area.
Can anyone help with this? Thanks.
Upvotes: 0
Views: 324
Reputation: 11838
use pointInside:withEvent: to tell it to not accept the point if it is outside the area.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return [self isPointWithinMyBounds:point];
}
- (BOOL) isPointWithinMyBounds:(CGPoint) point{
//determine if the point is within the rect
return NO;
}
the touchesMoved event will be the complex one. you would just discontinue drawing while outside the view.
but that should accomplish your desired effect.
Upvotes: 1
Reputation: 23634
you can put an invisible UIView on top of your current one, sized to your intended touch area. Then just add the gesture recognizer to that view only.
Upvotes: 0