0

現時点では、丸い矢印を円を描くように回転させています..これはクールですべてですが、他のビューのようにエンディングに関してはもう少し洗練されたものを望んでいます。 、これに対して同じことができるかどうか疑問に思っていました..これは私のコードです..

- (IBAction)animator:(id)sender
{
    [arrowRotation removeFromSuperview];

    //arrow animation
    arrowRotation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
    arrowRotation.frame = CGRectMake(148.0, 20.0, 30.0, 30.0);
    [self.view addSubview:arrowRotation];



    CABasicAnimation *fullRotation;
    fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    fullRotation.duration = 0.75f;
    fullRotation.repeatCount = 3;

    [arrowRotation.layer addAnimation:fullRotation forKey:@"360"];
}

だから私の質問は、3回転になるとこのアニメーションを遅くすることができるかということです..UIViewの使いやすさのように。それが理にかなっていれば..

どんな助けでも大歓迎です。

4

2 に答える 2

2

まず、この行fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];では、フロート((360*M_PI)/180)が円を 360 度回転させますが、数値が少し過剰です。これが意味することは、 に単純化できるということです2*M_PI

2番目:これをさらにカスタマイズしたい場合は、次を使用できますCAKeyframeAnimation

CAKeyframeAnimation *rotationAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];

NSArray *rotationValues = [NSArray arrayWithObjects: [NSNumber numberWithFloat: 0], [NSNumber numberWithFloat: (2*M_PI)], nil];

[rotationAnimation setValues:rotationValues];

NSArray *rotationTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],[NSNumber numberWithFloat:1.0f], nil];
[rotationAnimation setKeyTimes:rotationTimes];

NSArray *rotationTimingFunctions = [NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],  nil];
[rotationAnimation setTimingFunctions:rotationTimingFunctions];

rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.duration = 1;

[self.view.layer addAnimation:rotationAnimation forKey:@"animation"];

お役に立てれば!

于 2012-06-29T02:00:59.037 に答える
0

を使用UIView animateWithDuration:delay:options:animations:completion:してアニメーションを実行し、オプションを使用しますUIViewAnimationOptionCurveEaseOut。これは、更新された、i​​OS で推奨される UIView アニメーション メソッドであり、必要に応じて簡単に実行できます。

ドキュメントはこちら: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

ご不明な点がございましたら、お気軽にお問い合わせください。

于 2012-06-29T01:50:55.490 に答える