headkit
headkit

Reputation: 3327

Adding touch-area to UIView (iOS5)

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

Answers (2)

Kaan Dedeoglu
Kaan Dedeoglu

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

Ole Begemann
Ole Begemann

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:

  1. the subview is managed by its own view controller or

  2. you use the MainViewController directly to respond to touches in the subview or

  3. you create a UIView subclass that interprets touches on itself without the help of a view controller.

Upvotes: 2

Related Questions