ios – UIImageView同时重新调整大小并旋转UIImageView?

我的UIViewController中有一个UI
ImageView.我在上面设置了一个图像.我已完成轮换,如下所示.

- (void) runSpinAnimationOnView:(UIImageView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = repeat;

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

}

我称之为

[self runSpinAnimationOnView:_imageView duration:1.0 rotations:360 repeat:1.0];

现在我也希望调整相同的图像视图,但是从各方面都有相同的比例,我该怎么做.

简单地说,我想旋转UIImageView并同时调整它.

谢谢

最佳答案 简单地这样做,你可以根据需要按比例制作CGRectMake.它只是表明它将如何调整大小的方式.

- (void)rotateSpinningView
    {

        _imageView.frame = CGRectMake(_imageView.frame.origin.x+5,
                                      _imageView.frame.origin.y+5,
                                      _imageView.frame.size.width-10,
                                      _imageView.frame.size.height-10);

        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        _imageView.clipsToBounds = YES;


        [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
            [_imageView setTransform:CGAffineTransformRotate(_imageView.transform, M_PI_2)];
        } completion:^(BOOL finished) {
            if (finished && !CGAffineTransformEqualToTransform(_imageView.transform, CGAffineTransformIdentity)) {
                [self rotateSpinningView];
            }
        }];
    }

    - (IBAction)changeView:(UIButton *)sender {

        [self rotateSpinningView];

    }
点赞