Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all, an easy way to handle drag, scale and rotate is to use GestureRecognizers like the bellow one:</p> <pre><code> UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)]; [pinchRecognizer setDelegate:self]; [self.view addGestureRecognizer:pinchRecognizer]; UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)]; [rotationRecognizer setDelegate:self]; [self.view addGestureRecognizer:rotationRecognizer]; UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)]; [panRecognizer setMinimumNumberOfTouches:1]; [panRecognizer setMaximumNumberOfTouches:1]; [panRecognizer setDelegate:self]; [self.view addGestureRecognizer:panRecognizer]; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)]; [tapRecognizer setNumberOfTapsRequired:1]; [tapRecognizer setDelegate:self]; [self.view addGestureRecognizer:tapRecognizer]; </code></pre> <p>To handle multiple UIImageViews you may use the position of touched points, you can use the bellow functions to do so:</p> <pre><code>- (CGPoint)locationInView:(UIView*)view; - (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView*)view; </code></pre> <p>According to the number of touched you can use either the first or second function, and then see if the touched point is inside the frame of considered UIImageView, for example for scaling you can do as what is show in bellow:</p> <pre><code>-(void)scale:(id)sender { UIView * pinchView = [(UIPinchGestureRecognizer*)sender view]; CGPoint first_point = [sender locationOfTouch:0 inView:pinchView]; CGPoint second_point = [sender locationOfTouch:1 inView:pinchView]; if (CGRectContainsPoint(my_image_view.frame, first_point) &amp;&amp; CGRectContainsPoint(my_image_view.frame, second_point)) { [self.view bringSubviewToFront:pinchView]; if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { lastScale = 1.0; return; } CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]); CGAffineTransform currentTransform = my_image_view.transform; CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale); [my_image_view setTransform:newTransform]; lastScale = [(UIPinchGestureRecognizer*)sender scale];}} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload