首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >旋转CALayer 90度?

旋转CALayer 90度?
EN

Stack Overflow用户
提问于 2010-07-29 11:56:39
回答 5查看 37.4K关注 0票数 33

如何旋转CALayer 90度?我需要旋转一切,包括子层和坐标系。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-07-29 12:10:26

如果我要给它动画,我会在我的应用程序中使用这样的东西:

代码语言:javascript
复制
- (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;
}

当然,您可以在任何地方使用它,如果方法不适合您的需要,就不必从方法中返回它。

票数 13
EN

Stack Overflow用户

发布于 2010-07-29 12:02:31

Obj-C:

代码语言:javascript
复制
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * M_PI, 0.0, 0.0, 1.0);

斯威夫特

代码语言:javascript
复制
theLayer.transform = CATransform3DMakeRotation(90.0 / 180.0 * .pi, 0.0, 0.0, 1.0)

也就是说,转换层,使其旋转90度(π/2弧度),其中100%的旋转发生在z轴上。

票数 58
EN

Stack Overflow用户

发布于 2010-07-29 12:02:19

基本上是这样的:

CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI / 2.0); [myCALayer setAffineTransform:rotateTransform];

编辑:它将顺时针或逆时针旋转取决于平台(iOS或Mac )。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3362180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档