Will UIImageView resize and rotate UIImageView at the same time?

I have a UIImageView in my UIViewController. I set the image on it. I made a turn as shown below.

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

}

I call it

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

Now I also want to resize the image of one image, but with an equal share on all sides. How can i do this.

Simply, I want to rotate the UIImageView and resize it at the same time.

thank

+4
source share
3 answers

Just do it this way, you can do CGRectMake proportionally as you want. it's just a way to show how this will change.

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

    }
+2
source

. @"transform.scale",

- (void) runScaleAnimationOnView:(UIImageView*)view duration:(CGFloat)duration scale:(CGFloat)scale repeat:(float)repeat
{
    CABasicAnimation* scaleAnimation;
    scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.toValue = [NSNumber numberWithFloat: scale];
    scaleAnimation.duration = duration;
    scaleAnimation.repeatCount = repeat;

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

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

, @"position"

0

CGAffineTransformConcat will complete your task, which will combine two transformations into one and make as one animation. try it.

[UIView animateWithDuration: 3.0f
                      delay: 0
                    options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                 animations:^{

                     UIView *yourViewToBeAnimated = YourViewToBeSetHere;

                     CGAffineTransform animationToRotate = CGAffineTransformMakeRotation(45);

                     CGAffineTransform animationToScale = CGAffineTransformMakeScale(2, 2);//Double the size


                     yourViewToBeAnimated.transform = CGAffineTransformConcat(animationToScale, animationToRotate);


                 }
                 completion:^(BOOL finished) {




                 }
 ];
0
source

All Articles