Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了铸造 – Swift Double不能转换为CGFloat大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在尝试绘制一个简单的圆圈,当我得到以下行我得到错误“双不可转换到CGFloat在startAngle = 0.0 path.addArcWithCenter(center, radius: radius, startAngle: 0.0, endAngle: Float(M_PI) * 2.0, clockwise: truE) 我如何“铸造”0.0使它成为Swift中的CGFloat? 我写
我正在尝试绘制一个简单的圆圈,当我得到以下行我得到错误“双不可转换到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()    
    }

大佬总结

以上是大佬教程为你收集整理的铸造 – Swift Double不能转换为CGFloat全部内容,希望文章能够帮你解决铸造 – Swift Double不能转换为CGFloat所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。