Showing posts with label UILongPressGestureRecognizer. Show all posts
Showing posts with label UILongPressGestureRecognizer. Show all posts

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>.

Wednesday, July 27, 2011

How to add various kinds of UIGesturesRecognizer to your view?

       UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    [piece addGestureRecognizer:rotationGesture];
    [rotationGesture release];
    
    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
    [pinchGesture setDelegate:self];
    [piece addGestureRecognizer:pinchGesture];
    [pinchGesture release];
    
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    [panGesture setDelegate:self];
    [piece addGestureRecognizer:panGesture];
    [panGesture release];
    
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [piece addGestureRecognizer:longPressGesture];
    [longPressGesture release];







For more details..you can refer to Apple' Sample code called Touches.


Note: Writing blog after so long.. I was so busy travelling... hardly had any time on hand.. but now its getting better, I will have more time on hand to blog.