Showing posts with label UIGestureRecognizer. Show all posts
Showing posts with label UIGestureRecognizer. Show all posts

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.

Monday, April 11, 2011

Tutorial on UIGestureRecognizer

I am going to cover Gestures topic today.

We have 2 views on our ViewController , they toggle on the swipe gesture of the user.



You will need to define a view class with the gesture added to it as following


You will have to define a protocol in its header file to be able to talk to main controller class which we will implement below in the blog.

This is another view with another swipe gesture implemented on it.
 
Same as above class we will to create protocol in its header file as well to be able to talk to main view controller.














Now we have a view controller class, where above views are added as sub view.

Firstly , there is view 1 visible and view 2 is hidden.
User swipes to left, it will hide view 1 and  display view 2.
User swipes to right, it will hide view 2 again and display view 1.

You can the protocol methods implemented in this view controller class.






























You will have to include the class1 and class2 protocol in your view controller's header file as following:








You can download the code, to study the code more deeply.


Download Sample Code