ios - 如何旋转CAShapeLayer对象?

标签 ios objective-c core-animation uibezierpath cashapelayer

我基本上需要实现的是自定义按钮,该按钮需要在加号图标和带动画的复选标记之间切换。第一步,我尝试使用CAShapeLayer创建水平线,并尝试旋转一定角度。我不知道其中有什么问题。

 UIBezierPath *linePath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0,self.frame.size.width, 10)];

//shape layer for the line
CAShapeLayer *line = [CAShapeLayer layer];
line.backgroundColor = [UIColor redColor].CGColor;
line.path = [linePath CGPath];
line.fillColor = [[UIColor greenColor] CGColor];
line.frame = CGRectMake(0, 10, self.frame.size.width,10);
line.anchorPoint = CGPointMake(0.0, 0.5);
line.transform = CATransform3DMakeRotation(30, 0.0, 0.0, 1.0);
[self.layer addSublayer:line];

最佳答案

转换使用弧度,因此您应该使用

line.transform = CATransform3DMakeRotation(30 * M_PI/180, 0.0, 0.0, 1.0);

关于ios - 如何旋转CAShapeLayer对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28598456/

相关文章:

objective-c - 顺序核心动画的设计模式

objective-c - 让 GADInterstitialAd 在 iPad 上更频繁地加载 : possible?

iphone - Universal Ad-Hoc 版本确实安装在 ipad 上,但没有安装在 iphone 上

iphone - 实例变量未在内存中分配

添加 subview 时 iOS 奇怪的键盘隐藏行为

ios - CATextLayer foregroundColor 动画不适用于 iOS9,但适用于 iOS10 或更高版本

ios - iPhone 应用程序转换为通用,在设备上运行良好,但验证失败并显示消息 "Nib file not found"

ios - Xcode7 : How to mail crash report in swift

ios - UIDatePicker 作为带秒数的倒数计时器(Swift)

ios - UITableView 页脚,停止在内容上 float