views:

489

answers:

1

i would like to make 2 operations to an UIImageView zoom, rotate i have 2 problems

  1. i make an operation for zoom for ex. and when i try to make rotation the uiimeview is set to initial size, i would like to know how to keep the zoomed uiimageview and make the rotation from the zoomed image

  2. i would like to combine the zoom operation with rotation and i don't know ho to implement this

    • (void)viewDidLoad {

       foo = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 600, 800.0)];
          foo.userInteractionEnabled = YES;
       foo.multipleTouchEnabled  = YES;
          foo.image = [UIImage imageNamed:@"earth.jpg"];
       foo.contentMode = UIViewContentModeScaleAspectFit;
       foo.clipsToBounds = YES;
      
      
       [self.view addSubview:foo];
      

//---pinch gesture--- UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; [foo addGestureRecognizer:pinchGesture]; [pinchGesture release];

 //---rotate gesture--- 
 UIRotationGestureRecognizer *rotateGesture =
       [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotateGesture:)];
 [foo addGestureRecognizer:rotateGesture]; 
 [rotateGesture release];



       //---handle pinch gesture--- 
        -(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
         NSLog(@"Pinch");
         CGFloat factor = [(UIPinchGestureRecognizer *) sender scale];
         if (factor > 1) { 
          //---zooming in--- 
          sender.view.transform = CGAffineTransformMakeScale(
          lastScaleFactor + (factor-1),
          lastScaleFactor + (factor-1)); 
         } 
         else {
          //---zooming out--- 
          sender.view.transform = CGAffineTransformMakeScale(lastScaleFactor * factor, lastScaleFactor * factor);
         }
         if (sender.state == UIGestureRecognizerStateEnded) { 
          if (factor > 1) {
           lastScaleFactor += (factor-1); 
          } else {
           lastScaleFactor *= factor;
          }
         }
        }

        //---handle rotate gesture--- 
        -(IBAction) handleRotateGesture:(UIGestureRecognizer *) sender {
         CGFloat rotation = [(UIRotationGestureRecognizer *) sender rotation]; 
         CGAffineTransform transform = CGAffineTransformMakeRotation(rotation + netRotation); 
         sender.view.transform = transform;
         if (sender.state == UIGestureRecognizerStateEnded) { 
          netRotation += rotation;
         }
        }

Thanks

+1  A: 

I found something that may interest you on the stanford university website:

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2010-winter

on this site you will need to scroll down until you see the number 14: "Title: Lecture #14 - MultiTouch"

Download the: "14_MultiTouchDemo.zip"

In this example you can scale and rotate every image at the same time.

hope i helped :)

DailyDoggy
This demo doesn't use UIGestureRecognizer, it resolves the the touches meaning.
Ali El-sayed Ali