【问题标题】:Core Animation circle animation核心动画圈动画
【发布时间】:2014-10-15 15:08:32
【问题描述】:

我一直在尝试制作一个圆形 CALayer 以简单地在其中心旋转。我只能让它在错误的锚点上旋转。我试图改变这个锚点,但动画保持不变。

- (void)rotateImage {
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI*2];
rotationAnimation.duration = 1;
rotationAnimation.repeatCount = INFINITY;
[self.surroundingCircles addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

结果:https://www.dropbox.com/s/gmlxw1t2mle0au9/rotation.mov?dl=0

【问题讨论】:

  • 锚点是怎么设置的?
  • self.surroundingCircles.anchorPoint = CGPointMake(0.5, 0.5);
  • 尝试设置您正在转动的视图的中心:self.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
  • 我使用的是 CAShapeLayer 而不是视图。

标签: ios rotation core-animation cabasicanimation


【解决方案1】:

我必须先设置图层的框架:

self.surroundingCircles.frame = CGRectMake(0, 0, 22, 22);

【讨论】:

    猜你喜欢
    • 2010-10-21
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多