相关疑难解决方法(0)

Swift Double无法转换为CGFloat

当我到达以下行时,我正在尝试绘制一个简单的圆圈我得到错误"Double是不可转换为CGFloat下的 startAngle = 0.0

path.addArcWithCenter(center, radius: radius, startAngle: 0.0, endAngle: Float(M_PI) * 2.0, clockwise: true)
Run Code Online (Sandbox Code Playgroud)

如何"转换"0.0以使其在Swift中成为CGFloat?

我写的完整功能:

func drawCircle() {
    // Drawing code
    var bounds:CGRect = secondView.bounds
    var center = CGPoint()
    center.x = bounds.origin.x + bounds.size.width / 2.0
    center.y = bounds.origin.y + bounds.size.height / 2.0
    var radius = (min(bounds.size.width, bounds.size.height) / 2.0)
    var path:UIBezierPath = UIBezierPath()
    path.addArcWithCenter(center, radius: radius, startAngle: CGFloat(0.0), endAngle: Float(M_PI) * 2.0, clockwise: true)
    path.stroke()    
}
Run Code Online (Sandbox Code Playgroud)

casting cgfloat swift

24
推荐指数
2
解决办法
2万
查看次数

标签 统计

casting ×1

cgfloat ×1

swift ×1