我想改变anchorPoint,但保持视图在同一个地方.我试过NSLog-ing分词self.layer.position和self.center他们都保持不变,无论更改anchorPoint的.然而我的观点却在变化
关于如何做到这一点的任何提示?
self.layer.anchorPoint = CGPointMake(0.5, 0.5);
NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y);
self.layer.anchorPoint = CGPointMake(1, 1);
NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y);
Run Code Online (Sandbox Code Playgroud)
输出是:
2009-12-27 20:43:24.161 Type[11289:207] center point: 272.500000 242.500000
2009-12-27 20:43:24.162 Type[11289:207] center point: 272.500000 242.500000
Run Code Online (Sandbox Code Playgroud) 我想在左上角旋转图像,而不是中心.根据文档,我将anchorPoint属性设置为[0,1].视图在我的示例中旋转50°,但在它开始动画之前,视图会跳转到屏幕上的另一个点.
self.shakeTag.layer.anchorPoint = CGPointMake(0.0f, 1.0f);
[UIView beginAnimations:@"rotate" context:nil];
[self.shakeTag.layer setTransform:
CATransform3DRotate(CATransform3DIdentity,
radians(50.0), 0.0f, 0.0f, 1.0f)];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
radians() 定义如下:
static inline double radians (double degrees) {return degrees * M_PI/180;}
Run Code Online (Sandbox Code Playgroud)
当我使用4倍大小并且具有大量透明像素的图像时,我可以在默认锚点[0.5,0.5]处旋转它,但我不想浪费空间用于不可见像素.任何想法如何防止图层在旋转发生之前跳跃?