开发者

Intercept tap event in given condition

I created a view with a UIPickerView which is showed 开发者_StackOverflow社区when user push a button.

Now i need to make UIPickerView disappear when user tap anywhere on screen (obviously out of UiPickerView).

How can i intercept this tap only when UIPickerView is visible ? Thank you!


You may want to attach a UIGestureRecognizer to the main view. As soon as someone taps the main view somewhere, you can get an event and remove your UIPickerView. Write something like this in you ViewController:

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] 
                         initWithTarget:self action:@selector(viewWasTapped)];
[self.view addGestureRecognizer:tgr];

In you viewWasTapped method you'll receive all Taps on the ViewControllers view.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜