views:

65

answers:

1

I have a UIImageView, which I want to be able to resize and rotate etc.

Can a GestureRecognizer be added to the ImageView?

I would want to add a rotate and pinch recognizer to a UIImageView which would be created at runtime.

How does one add these recognizers?

Thanks

+2  A: 

Check that userInteractionEnabled is YES on the UIImageView. Then you can add a gesture recognizer.

imageView.userInteractionEnabled = YES;
UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc] 
    initWithTarget:self action:@selector(handlePinch:)];
pgr.delegate = self;
[imageView addGestureRecognizer:pgr];
[pgr release];
:
:
- (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
  //handle pinch...
}
aBitObvious
Thanks. Will this not resize the image as pinching does, or how would this be handled to resize the image as the pinch gesture is recognized?
alJaree
No, this just shows how to add the gesture recognizers. You have to do the actual zoom/rotate yourself in the gesture handlers. See the sample app [Touches_GestureRecognizers](http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007435) on how to do the zoom/rotate.
aBitObvious
Thanks a lot. +1 :P
alJaree