Nil 与预期的参数类型 CGAffineTransform 不兼容
Nil is not compatible with expected argument type CGAffineTransform
我正在尝试绘制路径: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()
}
尝试了一些将 nil 替换为 0, options: nil, options: [ ]
none 的方法。
在@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()
}
CGMutablePath
在Swift3中添加弧的函数签名为
func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, transform: CGAffineTransform = default)
在你的情况下(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()!
并删除所有其他 !
。
我正在尝试绘制路径: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()
}
尝试了一些将 nil 替换为 0, options: nil, options: [ ]
none 的方法。
在@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()
}
CGMutablePath
在Swift3中添加弧的函数签名为
func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, transform: CGAffineTransform = default)
在你的情况下(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()!
并删除所有其他 !
。