【发布时间】: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