Question

I have a view, inside that view I have an UIImageview but inside this UIImageview I have 3 more UIImageview, this 3 UIImageview I can drag them and resize them, the problem is that when i resize one of them all of them return to the original position, why is this happening ?

UPDATE: I use this for dragging the image

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
 CGPoint translation = [recognizer translationInView:_photo];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
                                     recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:_photo];}

This for resizing, using an slider

- (IBAction)sizePhoto:(UISlider *)sender {

 switch (cambiaSize) {
 case 1:
    [_imagen1 setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];
    break;
case 2:
    [_imagen2 setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];
    break;
case 3:
    [_imagen3 setTransform:CGAffineTransformMakeScale(sender.value, sender.value)];
    break;}}

I have also used this for resizing

_imagen1.transform = CGAffineTransformScale(self.view.transform,sender.value, sender.value);

and I also flip horizontally the image using this

_imagen2.transform = CGAffineTransformScale(_imagen2.transform,1.0, 1.0);

I would like to keep the transformation while doing any of this actions...

Was it helpful?

Solution

This could be a consequence of using auto layout. If you directly change the frame of an object, it will revert to the frame defined by the constraints when some other action causes the view to redraw. You either need to turn off auto layout, or change the position of your views by modifying their constraints.

OTHER TIPS

Use CGAffineTransformScale instead of CGAffineTransformMakeScale. 'MakeScale' creates a whole new identity transform with applied scale whereas the former method simply applies a scale to the pre-existing transform.

    UIImageView *imageView              = [[UIImageView alloc] init];
    CGFloat exampleValueA = 90.0f, exampleValueB = 90.0f;
    imageView.transform                 = CGAffineTransformScale(imageView.transform, exampleValueA, exampleValueB);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top