开发者

Detect if touch on a UIView

开发者 https://www.devze.com 2023-04-05 04:20 出处:网络
I have a v开发者_开发百科iewController that has a UIView as a subview, I was wondering how i might tell if and only if the user has clicked on the UIView from the Viewcontroller.

I have a v开发者_开发百科iewController that has a UIView as a subview, I was wondering how i might tell if and only if the user has clicked on the UIView from the Viewcontroller.

Is this possible? Thanks!


Check out the UITapGestureRecognizer documentation:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html

You'll instantiate a UITapGestureRecognizer in your UIViewController, using initWithTarget:action (passing a selector which will handle your tap). Then add the UIGestureRecognizer to your UIView via the addGestureRecognizer method.


You could use the touchesBegan, touchesMoved and touchesEnded methods. Depending on the application, you could as well use touchesCancelled.

If none of these work, you might want to use UIGestureRecognizers - UIPanGestureRecognizer and UITapGestureRecognizer.

Just in case it might be helpful, you can also use two gesture recognizers at the same time using the method

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
0

精彩评论

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