加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

铸造 – Swift Double不能转换为CGFloat

发布时间:2020-12-14 05:52:13 所属栏目:百科 来源:网络整理
导读:我正在尝试绘制一个简单的圆圈,当我得到以下行我得到错误“双不可转换到CGFloat在startAngle = 0.0 path.addArcWithCenter(center,radius: radius,startAngle: 0.0,endAngle: Float(M_PI) * 2.0,clockwise: true) 我如何“铸造”0.0使它成为Swift中的CGFloa
我正在尝试绘制一个简单的圆圈,当我得到以下行我得到错误“双不可转换到CGFloat在startAngle = 0.0
path.addArcWithCenter(center,radius: radius,startAngle: 0.0,endAngle: Float(M_PI) * 2.0,clockwise: true)

我如何“铸造”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,startAngle: CGFloat(0.0),clockwise: true)
    path.stroke()    
}
将需要CGFloat的值转换为CGFloat。
path.addArcWithCenter(center,radius: CGFloat(radius),endAngle: CGFloat(M_PI) * 2.0,clockwise: true)

如果你刚刚传递一个文字,startAngle可能不需要转换。还要注意,这不是C风格的演员,而是实际上在不同的Swift类型之间进行转换。

编辑:看你的整个功能,这是有效的。

func drawCircle() {
        // Drawing code
        var bounds:CGRect = self.view.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,endAngle: CGFloat(Float(M_PI) * 2.0),clockwise: true)
        path.stroke()    
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读