开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜