我正在尝试绘制路径:CGMutablePath
但是在添加路径时我遇到了问题。 Nil与预期的参数类型'UnsafePointer'CGAffineTransform'
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let path = CGMutablePath()
CGPathAddArc(path, nil, centerX, centerY, radius, -CGFloat(M_PI/2), CGFloat(GLKMathDegreesToRadians(currentAngle)), false)
context!.addPath(path)
context!.setStrokeColor(UIColor.blue.cgColor)
context!.setLineWidth(3)
context!.strokePath()
}
尝试使用0, options: nil, options: [ ]
替换nil,但这些都没有。
在@vadian回答的帮助下。 解决方案:
override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()!
let path = CGMutablePath()
path.addArc(center: CGPoint(x:centerX, y:centerY), radius: radius, startAngle: -(CGFloat.pi / 2), endAngle: CGFloat(GLKMathDegreesToRadians(currentAngle)), clockwise: false)
context.addPath(path)
context.setStrokeColor(UIColor.blue.cgColor)
context.setLineWidth(3)
context.strokePath()
}
答案 0 :(得分:3)
func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, transform: CGAffineTransform = default)
函数在Swift 3中添加弧的签名是
center
在您的情况下(CGPoint
必须是path.addArc(center: CGPoint(x:centerX, y:centerY),
radius: radius,
startAngle: -(CGFloat.pi / 2),
endAngle: CGFloat(GLKMathDegreesToRadians(currentAngle)),
clockwise: false)
)
let context = UIGraphicsGetCurrentContext()!
避免四个感叹号直接解开上下文
!
并删除所有其他case
。