如何旋转CALayer 90度?我需要旋转一切,包括子层和坐标系。
发布于 2010-07-29 12:10:26
如果我要给它动画,我会在我的应用程序中使用这样的东西:
- (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;
}当然,您可以在任何地方使用它,如果方法不适合您的需要,就不必从方法中返回它。
发布于 2010-07-29 12:02:31
Obj-C:
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * M_PI, 0.0, 0.0, 1.0);斯威夫特
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * .pi, 0.0, 0.0, 1.0)也就是说,转换层,使其旋转90度(π/2弧度),其中100%的旋转发生在z轴上。
发布于 2010-07-29 12:02:19
基本上是这样的:
CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI / 2.0); [myCALayer setAffineTransform:rotateTransform];
编辑:它将顺时针或逆时针旋转取决于平台(iOS或Mac )。
https://stackoverflow.com/questions/3362180
复制相似问题