Jon*_*pan 50
OBJ-C:
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * M_PI, 0.0, 0.0, 1.0);
Run Code Online (Sandbox Code Playgroud)
迅速:
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * .pi, 0.0, 0.0, 1.0)
Run Code Online (Sandbox Code Playgroud)
也就是说,将层变换为使其旋转90度(π/ 2弧度),其中100%的旋转发生在z轴周围.
Rab*_*Rab 13
如果我动画它我在我的应用程序中使用这样的东西:
- (NSObject *) defineZRotation {
// Define rotation on z axis
float degreesVariance = 90;
// object will always take shortest path, so that
// a rotation of less than 180 deg will move clockwise, and more than will move counterclockwise
float radiansToRotate = DegreesToRadians( degreesVariance );
CATransform3D zRotation;
zRotation = CATransform3DMakeRotation(radiansToRotate, 0, 0, 1.0);
// create an animation to hold "zRotation" transform
CABasicAnimation *animateZRotation;
animateZRotation = [CABasicAnimation animationWithKeyPath:@"transform"];
// Assign "zRotation" to animation
animateZRotation.toValue = [NSValue valueWithCATransform3D:zRotation];
// Duration, repeat count, etc
animateZRotation.duration = 1.5;//change this depending on your animation needs
// Here set cumulative, repeatCount, kCAFillMode, and others found in
// the CABasicAnimation Class Reference.
return animateZRotation;
}
Run Code Online (Sandbox Code Playgroud)
当然你可以在任何地方使用它,不必从方法返回它,如果那不适合你的需要.
基本上是这样的:
CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI / 2.0);
[myCALayer setAffineTransform:rotateTransform];
编辑:它将顺时针或逆时针旋转,具体取决于平台(iOS或Mac OS).
| 归档时间: |
|
| 查看次数: |
32490 次 |
| 最近记录: |