开发者

Check if UIView is touched?

开发者 https://www.devze.com 2023-01-26 09:05 出处:网络
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 vie

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号