Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if UIView is touched?

Hey, I want to be able to check if user touches my UIView so I can dismiss my picker how can I do it actually? Thanks!

like image 485
Samuli Lehtonen Avatar asked Nov 21 '10 20:11

Samuli Lehtonen


1 Answers

Try adding a UITapGestureRecognizer to your UIView class in the viewDidLoad of the UIViewController subclass that contains your UIView. It would look something like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(viewTapped:)];
    tap.numberOfTapsRequired = 1;
    [self.aView addGestureRecognizer:tap];
    [tap release];
}

Then implement a handler for the tap which, based on the above code, would look like this:

-(void)viewTapped:(UITapGestureRecognizer *)recognizer {
    //Add in your picker dismissal code here
}

Hope this helps,

Justin

like image 182
justinkmunger Avatar answered Sep 22 '22 10:09

justinkmunger