Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag, scale and rotate multiple UIImageviews
    primarykey
    data
    text
    <p>I've got it so far that I can move, scale and rotate all the objects, but the multiple objects all move together. I want them to move seperate. I guess I have to change the objectatIndex to 1, but it just crashes.</p> <p>I've used the following code:</p> <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSArray *allTouches = [touches allObjects]; UITouch* t; if([[event allTouches] count]==1){ if (CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:0] locationInView:theimageView]) &amp;&amp; CGRectContainsPoint([imageViewauto frame], [[allTouches objectAtIndex:0] locationInView:theimageView])) { t=[[[event allTouches] allObjects] objectAtIndex:0]; touch1=[t locationInView:nil]; } }else{ t=[[[event allTouches] allObjects] objectAtIndex:0]; touch1=[t locationInView:nil]; t=[[[event allTouches] allObjects] objectAtIndex:1]; touch2=[t locationInView:nil]; } } -(double)distance:(CGPoint)point1 toPoint:(CGPoint)point2 { double deltaX, deltaY; deltaX = point1.x - point2.x; deltaY = point1.y - point2.y; return sqrt(deltaX * deltaX + deltaY * deltaY); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint currentTouch1; CGPoint currentTouch2; NSArray *allTouches = [touches allObjects]; UITouch* t; float scale,rotation; if([[event allTouches] count]==1){ t=[[[event allTouches] allObjects] objectAtIndex:0]; if (CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:0] locationInView:theimageView]) &amp;&amp; CGRectContainsPoint([imageViewauto frame], [[allTouches objectAtIndex:0] locationInView:theimageView])) { touch2=[t locationInView:nil]; Birdie.center=CGPointMake(Birdie.center.x+touch2.x-touch1.x,Birdie.center.y+touch2.y-touch1.y); imageViewauto.center=CGPointMake(imageViewauto.center.x+touch2.x-touch1.x,imageViewauto.center.y+touch2.y-touch1.y); touch1=touch2; } } else if([[event allTouches] count]==2) { t=[[[event allTouches] allObjects] objectAtIndex:0]; currentTouch1=[t locationInView:nil]; t=[[[event allTouches] allObjects] objectAtIndex:1]; currentTouch2=[t locationInView:nil]; double distance1 = [self distance:currentTouch1 toPoint:currentTouch2]; double distance2 = [self distance:touch1 toPoint:touch2]; if (distance2 == 0) { //handle the case where distance is zero } else { scale =distance1 / distance2;} rotation=atan2(currentTouch2.y-currentTouch1.y, currentTouch2.x-currentTouch1.x)-atan2(touch2.y-touch1.y,touch2.x-touch1.x); if(isnan(scale)){ scale=1.0f; } NSLog(@"rotation %f",rotation); NSLog(@"scale %f",scale); if (CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:0] locationInView:theimageView]) &amp;&amp; CGRectContainsPoint([imageViewauto frame], [[allTouches objectAtIndex:0] locationInView:theimageView])) { Birdie.transform=CGAffineTransformScale(Birdie.transform, scale,scale); Birdie.transform=CGAffineTransformRotate(Birdie.transform, rotation); imageViewauto.transform=CGAffineTransformScale(imageViewauto.transform, scale,scale); imageViewauto.transform=CGAffineTransformRotate(imageViewauto.transform, rotation); } else // In case of scaling or rotating the background imageView { imageView.transform=CGAffineTransformScale(imageView.transform, scale,scale); imageView.transform=CGAffineTransformRotate(imageView.transform, rotation); } touch1=currentTouch1; touch2=currentTouch2; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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