0

我想创建两个方法... StartSpin 和 StopSpin。在 StartSpin 中,我需要一个 UIImageView 来旋转 360 度并循环它,直到我调用 StopSpin。

到目前为止,这是我的 StartSpin ......

private void StartSpin () {         
    UIView.Animate (
        1,
        0,
        UIViewAnimationOptions.Repeat,
        () => { 
            CGAffineTransform t = CGAffineTransform.MakeIdentity();
            t.Translate(0, 0);
            t.Rotate((float)(3.14));
            this._imageViewWait.Transform = t;
        },
        () => {}
    );
}

这是我的两个问题...

  1. 如何让它旋转 360 度?

  2. 我应该在 StopSpin 方法中使用什么命令来停止旋转?

谢谢

魔精

4

1 回答 1

0

要使图像旋转,您可以使用(旋转 1 度):

CGAffineTransform rotate = CGAffineTransformMakeRotation( 1.0 / 180.0 * 3.14 );
[imageView setTransform:rotate];

要使图像旋转,只需创建一个持续调用此方法的计时器(并增加度数)。此外,如果您想继续旋转,请创建一个布尔值来跟踪。

要停止旋转,只需将 bool 值更改为 false。然后,继续更新,直到到达开头(度数为 360 或 0)并且 bool 值为 false。

如果您不想继续旋转直到图像回到原来的位置,只需消除&& degrees == 0

在代码中:

-(void)startSpinning {
    degrees = 0;
    continueSpinning = true;
    [self continueSpinning];
}

-(void)continueSpinning {
    degrees = (degrees + 1) % 360;

    CGAffineTransform rotate = CGAffineTransformMakeRotation( degrees / 180.0 * 3.14 );
    [imageView setTransform:rotate];

    if(!continueSpinning && degrees == 0) return;
    else [self performSelector:@selector(continueSpinning) withObject:nil afterDelay:0.1f];
}

-(void)stopSpinning {
    continueSpinning = false;
}
于 2012-04-26T00:32:09.640 回答