多次旋转图像并停止在所需的角度? [英] Rotating Image multiple times and stopping at desired degree?

查看:86
本文介绍了多次旋转图像并停止在所需的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了各种方法,却找不到解决方法。我在互联网上进行了很多搜索,但无法弄清楚。

i had tried various method and couldn't figure out how to achieve this.i searched on internet a lot but can't figure out.

我有一个 ImageView (一个旋转的轮子),我想将其旋转360度10次(这只是为了用户感觉快速旋转的车轮),然后我想将其旋转特定值,例如90度(但可能会有所不同)。

i have an ImageView (a wheel which spins) , i want to rotate it by 360 degree for 10 times(this is to just give user feel of fast turning wheel) , and then i want to rotate it by particular value say 90 degree( but it might be varying).

此动画完成后,我想要将ImageView恢复到初始位置。

after this animation finishes i want to bring ImageView back to the initial position.

我该如何实现?
提前谢谢。

how do i achieve this ? Thanks in advance.

推荐答案

好,我发现了如何做到这一点。
i使用以下方法旋转360度10次,然后旋转特定角度。

well i found out how to do this. i used below method to rotate by 360 degree for 10 times , and then rotate by particular degree.

-(void)rotate:(int)degreeToRotate
{
  CGFloat radians = (M_PI/180) * degreeToRotate;
  [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations: ^{
    //configuring to rotate 360 degree 10 times
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 10;

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

    } completion:^(BOOL finished) {
        //rotate by particular degree
        [ UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        // -radians, to ensure clockwise rotation
        self.scoreImageView.transform = CGAffineTransformMakeRotation(-radians);

         }  completion:^(BOOL finished) {
                //method call to reset image original position 
                [self performSelector:@selector(resetPosition) withObject:nil afterDelay:3];
        }];

 }];

}

以下方法用于将图像重置为原始位置。

below method is used to reset image to original position.

-(void)resetPosition
{
    [UIView animateWithDuration:0.2 animations:^() {

          self.scoreImageView.transform = CGAffineTransformIdentity;
    }]; 
}

这篇关于多次旋转图像并停止在所需的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆