-1

我有一个视图,在那个视图里面我有一个 UIImageview 但在这个 UIImageview 里面我还有 3 个 UIImageview,这 3 个 UIImageview 我可以拖动它们并调整它们的大小,问题是当我调整其中一个的大小时它们都返回到原来的位置,为什么会这样?

更新:我用它来拖动图像

- (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];}

这用于调整大小,使用滑块

- (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;}}

我也用它来调整大小

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

我也使用这个水平翻转图像

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

我想在执行任何这些操作时保持转换......

4

2 回答 2

1

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.

于 2013-11-11T16:32:38.440 回答
0

使用 CGAffineTransformScale 而不是 CGAffineTransformMakeScale。'MakeScale' 创建了一个具有应用比例的全新身份变换,而前一种方法只是将比例应用于预先存在的变换。

    UIImageView *imageView              = [[UIImageView alloc] init];
    CGFloat exampleValueA = 90.0f, exampleValueB = 90.0f;
    imageView.transform                 = CGAffineTransformScale(imageView.transform, exampleValueA, exampleValueB);
于 2013-11-11T16:04:51.423 回答