Helium3 Helium3 - 1 year ago 95
iOS Question

UIGestureRecognizer on UIImageView

I have a

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

Can a
be added to the

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

How does one add these recognizers?

Answer Source

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