Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在点上进行变换旋转的动画_Ios_Objective C_Core Animation - Fatal编程技术网

Ios 在点上进行变换旋转的动画

Ios 在点上进行变换旋转的动画,ios,objective-c,core-animation,Ios,Objective C,Core Animation,我正在尝试设置视图层在任意点上旋转的动画。动画的开始位置将是从结束和最终位置旋转90º。此视图占据除状态栏之外的所有屏幕 我尝试使用以下代码(带有平移,然后是旋转和反平移),但是,不管它的开始和结束如何,动画不是以点为中心,而是围绕点摆动 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"]; animation.duration = 1; animation.additive =

我正在尝试设置视图层在任意点上旋转的动画。动画的开始位置将是从结束和最终位置旋转90º。此视图占据除状态栏之外的所有屏幕

我尝试使用以下代码(带有平移,然后是旋转和反平移),但是,不管它的开始和结束如何,动画不是以点为中心,而是围绕点摆动

CABasicAnimation *animation = [CABasicAnimation   animationWithKeyPath:@"transform"];
animation.duration = 1;
animation.additive = YES;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeRemoved;

//The point that should be used as the center of rotation
CGPoint cursorCenter=self.angleCenter;
//The center of the view
CGPoint linesCenter=lines.center;

//The transformation: translate->rotate->anti-translate
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, cursorCenter.x-linesCenter.x, cursorCenter.y-linesCenter.y, 0.0);
transform = CATransform3DRotate(transform, degreesToRadians(-90), 0.0, 0.0, -1.0);
transform = CATransform3DTranslate(transform, linesCenter.x-cursorCenter.x, linesCenter.y-cursorCenter.y, 0.0);

animation.fromValue =[NSValue valueWithCATransform3D:transform];
animation.toValue =[NSValue valueWithCATransform3D:CATransform3DIdentity];    

[lines.layer addAnimation:animation forKey:@"90rotation"];

我做错了什么?

在特定点上旋转不必进行平移。只需更改层
锚点
,即可调整旋转中心

变换的原点是“中心”特性的值,或 层的“锚点”属性(如果已更改)

关于定位点以及如何指定它:

可以使用单位坐标指定此特性的值 空间此属性的默认值为(0.5,0.5),即 表示层边界矩形的中心。全几何 对视图的操作发生在指定点附近。对于 例如,将旋转变换应用到具有默认值的图层 定位点使图层围绕其中心旋转更改 锚定点到另一个位置会导致层移动 围绕新点旋转。


基于和

我不久前写了一篇关于这种动画的文章。那可能值得一读,我已经读过了。问题是我用的是自动布局。堆栈溢出链接上的解决方案谈到了层转换,但我已经在使用它了。