我想旋转我的椭圆,但我没能做到。
我试着做一个CGAffineTransform,但是我的矩形消失了,我也试着做一个CATransformRotate或者类似这样的笔记,但是没能正确使用它
let ovalPath = UIBezierPath(ovalIn: CGRect(x: 100, y: 100, width: 10, height: 15))
UIColor.gray.setFill()
ovalPath.fill()
let rotation = CGAffineTransform(rotationAngle: CGFloat(M_PI / 3.0))
ovalPath.apply(rotation)
let note = CAShapeLayer()
note.path = ovalPath.cgPath
note.fillColor = UIColor.black.cgColor
view.layer.addSublayer(note)发布于 2018-05-29 21:41:51
由于cgrect中的x/y偏移量(它围绕(0,0)旋转),您正在将路径旋转出屏幕。尝试此操作并稍微旋转ccw,以查看旋转行为是否正常工作。如果希望图层位于坐标100,100处,可以使用另一个变换来移动它:
let ovalPath = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 10, height: 15))
UIColor.gray.setFill()
ovalPath.fill()
let rotation = CGAffineTransform(rotationAngle: -CGFloat(M_PI / 3.0))
ovalPath.apply(rotation)
let note = CAShapeLayer()
note.path = ovalPath.cgPath
note.fillColor = UIColor.black.cgColor
view.layer.addSublayer(note)https://stackoverflow.com/questions/50584817
复制相似问题