Animate Rotating UIImageView

前端 未结 5 1692
予麋鹿
予麋鹿 2021-02-08 03:07

I want to rotate a UIImageView by roughly 10 degrees left/right but have a smooth animation, rather than a sudden turn which I see using:

play         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 03:45

    I use some code like this to achieve a similar effect (though I rotate it by 360 degrees):

    CABasicAnimation *rotate;
    rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotate.fromValue = [NSNumber numberWithFloat:0];
    rotate.toValue = [NSNumber numberWithFloat:deg2rad(10)];
    rotate.duration = 0.25;
    rotate.repeatCount = 1;
    [self.view.layer addAnimation:rotate forKey:@"10"];
    

    I use code very similar to this to spin an image view.

提交回复
热议问题