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
精彩评论