Check if UIView is touched?
Hey, I want to be able to chec开发者_高级运维k if user touches my UIView so I can dismiss my picker how can I do it actually? Thanks!
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
精彩评论