Wednesday, February 15, 2012

How to combine 2 or more UIGesture ?

So, this is useful when you are trying to implement following(this is just one of the case, you may have some other scenario but this article basically tells you to combine UIGestures):

Following a long press you  move the a view around so you are basically implementing  UILongPressGestureRecognizer and UIPanGestureRecognizer. You have to write following delegate methods in your .m



 #pragma mark - Gesture Delegate Method  
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer  
 {  
   return YES;  
 }  
 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer  
 {  
   return YES;  
 }  
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{  
   return YES;  
 }  





If you use following delegate methods, then you wont have to have discrete gestures(which is how it is by default), it will start looking for long gesture and pan gesture (simultaneously)without any break in between.

And ofcourse don't forget to add the protocol in your .h <UIGestureRecognizerDelegate>.

No comments:

Post a Comment