我有一个尺寸为 12x44 的时钟针图像。下面的代码是我试图沿时钟方向旋转它的代码
Code :
-(void)rotationLargeAnimation:(UIView *) itemView withDuration:(float) durat withDirection:(int)intDirect {
CABasicAnimation *rotation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation1.fromValue = [NSNumber numberWithFloat:0];
rotation1.toValue = [NSNumber numberWithFloat:(2*M_PI)];
rotation1.duration = durat; // Speed
rotation1.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
itemView.layer.anchorPoint = CGPointMake(0.5,0.2);
[itemView.layer addAnimation:rotation1 forKey:@"Spin"];
}
旋转时钟针时,它是根据顶部位置旋转的。我如何根据底部位置旋转针。感谢任何帮助。提前致谢。
最佳答案
anchor 设置图层在标准化坐标中旋转的点(0, 0)是左上角,(0.5, 0.5)是中心(默认),(1.0, 1.0)是右下角。因此,您可能希望将其设置在 (0.5, 1.0) 附近的某个位置,这是 X 轴的中心和 Y 轴的底部(可能会从底部偏移,具体取决于您的针的形状)。
关于ios - 如何在CABasicanimation中设置 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24800039/