Reputation: 3327
I have a MainView with MainViewController. Now I want to add a specific area where I want to register touches (painting in a specific area). How could I do this? I thought about adding a sub-view with its own sub-viewcontroller, but this guy tells this is not a good approach.
Upvotes: 0
Views: 411
Reputation: 14851
Add a custom view as a property, called touchArea
-(void) touchesBegan/Moved/Ended (NSSet *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self.view];
if (CGRectContainsPoint(touchArea.frame, location))
//code
}
}
Upvotes: 1
Reputation: 135558
The post you linked to is partially out of date because it was written before Apple introduced support for View Controller Containment in iOS 5.
That said, it's your choice whether:
the subview is managed by its own view controller or
you use the MainViewController
directly to respond to touches in the subview or
you create a UIView
subclass that interprets touches on itself without the help of a view controller.
Upvotes: 2