简体   繁体   中英

How to rotate CAShapeLayer object?

What basically i need to implement is custom button that need to switch between plus icon and a check mark with animation. As a first step i am trying to create horizontal line with CAShapeLayer and trying to rotate by some angle. I cannot figure out what is wrong in it.

 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);

我使用此库添加了我添加的库, http://code4app.net/ios/BZAnimationButton/5477ed87e24741f10bb03ca0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM