4

部分的な円をループしてアニメーションを実現しようとしていますが、180 度しか回転せず、0 度から 180 度に戻ります。そのため、180 度から 360 度への急激なジャンプがあります。円形の画像オブジェクトをジャンプせずに連続的に回転させるにはどうすればよいですか? これが私の現在のコードです:

    UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear|UIViewAnimationOptionRepeat;

    [UIView animateWithDuration:ROTATE_ANIMATION_DURATION/2 delay:0 options:options 
       animations:^{
           view.transform = CGAffineTransformRotate(transform, M_PI);}//1st step of animation finished
       completion:^(BOOL finished) {
             [UIView animateWithDuration:ROTATE_ANIMATION_DURATION/2 delay:0 options:options 
                animations:^{
                    view.transform = CGAffineTransformRotate(transform, M_PI);} //2nd step of animation finished
                completion:^(BOOL finished) {nil;
                }];
4

4 に答える 4

14

UI オブジェクトを回転させ、アニメーションを 360 度回転させる
には、QuartzCore フレームワークをプロジェクトに追加し、

#import QuartzCore/QuartzCore.h

オブジェクトのアニメーションを追加:

 CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    fullRotation.duration = 6;
    fullRotation.repeatCount = 1e100f;
    [myview.layer addAnimation:fullRotation forKey:@"360"];
于 2012-09-11T06:56:28.163 に答える
3

ビューを 360 度回転させるために使用する古いコードを見つけました。QuartzCore をインポートする必要があります。

CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.zRad"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0];

rotationAnimation.duration = 3;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = INFINITY;
rotationAnimation.timingFunction = 
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

[viewToAnimate.layer addAnimation:rotationAnimation forKey:@"transform.rotation.zRad"];
于 2012-09-11T06:50:49.820 に答える