CABasic对象周围的动画(360度)

时间:2014-08-06 23:52:52

标签: ios objective-c animation rotation cabasicanimation

这是我的动画代码:

  CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    fullRotation.duration = 4;
    fullRotation.repeatCount= 1000;
    [[stick layer] addAnimation:fullRotation forKey:@"60"];

      fullRotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

我试图旋转"坚持"它本身周围,但它似乎围绕另一个点旋转,这默认是原点。我该怎么做才能让它绕自身完成360度旋转?提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果你想改变棍子使用的锚点:

stick.layer.anchorPoint = CGPointMake(1.0,1.0);

https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/anchorPoint

我使用的旋转代码:

CABasicAnimation *rotateAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotateAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    rotateAnim.fromValue = [NSNumber numberWithFloat:0];
    rotateAnim.toValue = [NSNumber numberWithFloat:(360 * M_PI / 180.0f)];
    rotateAnim.repeatCount = HUGE_VALF;
    rotateAnim.duration = 2.5;
    rotateAnim.removedOnCompletion = NO;

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