我试图在 Swift 中画一个圆圈,但是当我编写代码时,出现错误“无法找到接受所提供参数的‘init’重载。
在 UIBezierPath 类中有一个 init 函数:
init(arcCenter center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool) -> UIBezierPath
但是当我用这段代码声明它时,我得到了错误。我需要将任何变量转换为其他类型吗?但如果我在 iphone 4 中编译它,我不会收到错误,只有在 iphone 5/5s 中才会出现错误。如何正确声明这一点?
let arcCenter = CGPoint(x: CGRectGetMidX(self.bounds), y: CGRectGetMidY(self.bounds))
let radius = Float(min(CGRectGetMidX(self.bounds) - 1, CGRectGetMidY(self.bounds)-1))
let circlePath : UIBezierPath = UIBezierPath(arcCenter: arcCenter, radius: radius, startAngle: -rad(90), endAngle: rad(360-90), clockwise: true)
Thanks!
您需要将 UIBezierPath 的 init 方法中作为参数传递的值转换为 CGFloat,因为 Swift 将它们视为 Double 或 Float (let radius)。
let circlePath : UIBezierPath = UIBezierPath(arcCenter: arcCenter, radius:
CGFloat(radius), startAngle: CGFloat(-rad(90)), endAngle: CGFloat(rad(360-90)), clockwise: true)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)