Why after rotating UIImageView size is getting changed?

后端 未结 2 1609
离开以前
离开以前 2021-02-06 10:53

I\'m new in using transformations. And still confusted how they are working.

What I\'m trying to do, is to rotate my UIImageView with given angle. But after rotating, it

2条回答
  •  囚心锁ツ
    2021-02-06 11:11

    Do not set the contentMode which UIImageView inherits from UIView and leads to the changes in frame according to scaling,transformation,device rotation in accordance to the UIViewContentMode you select.

    Also if you just want to rotate you can just change the frame using :-

    [UIView beginAnimations:@"Rotate" context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        CGRect frame=yourView.frame;
        frame.origin.y+=distance you want to rotate;
        yourview.frame=frame;
        [UIView commitAnimations];
    }
    

    if you dont want the animation just change the frame

    Try Using This :-

    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = [NSNumber numberWithFloat:0.0f];
    animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
    animation.duration = 0.5f;            
    animation.repeatCount = HUGE_VALF;     // HUGE_VALF is defined in math.h so import it
    [self.reloadButton.imageView.layer addAnimation:animation forKey:@"rotation"];
    

提交回复
热议问题