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.

第二:如果你想更多地定制这个,你可以使用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。这是 iOS 上更新后的首选 UIView 动画方法,可让您轻松完成所需的操作。

这里的文档:http: //developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

如果您有任何问题,请告诉我!

于 2012-06-29T01:50:55.490 回答