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

Swift – UIBezierPath调用中的额外参数’radius’

发布时间:2020-12-14 04:28:16 所属栏目:百科 来源:网络整理
导读:我正在调整Objective-C库( STKSpinnerView)到Swift,我无法解决这个错误: func getRadius() - CGFloat { var r : CGRect = CGRectInset(self.bounds,self.wellThickness/2.0,self.wellThickness/2.0) var w : CGFloat = r.size.width var h : CGFloat = r.si
我正在调整Objective-C库( STKSpinnerView)到Swift,我无法解决这个错误:

func getRadius() -> CGFloat {
    var r : CGRect = CGRectInset(self.bounds,self.wellThickness/2.0,self.wellThickness/2.0)
    var w : CGFloat = r.size.width
    var h : CGFloat = r.size.height

    if w > h {
        return h/2.0
    }else{
        return w/2.0
    }
}

override func layoutSubviews()  {
    super.layoutSubviews()

    var bounds : CGRect = self.bounds
    var wt : CGFloat = self.wellThickness
    var outer : CGRect = CGRectInset(self.bounds,wt/2.0,wt/2.0)
    var inner : CGRect = CGRectInset(self.bounds,wt,wt)

    var innerPath : UIBezierPath = UIBezierPath(ovalInRect: inner)
    var arcCenter = CGPointMake(CGRectGetMidX(outer),CGRectGetMidY(outer))
    var radius = self.getRadius()
    var startAngle = -(CGFloat(M_PI_2))
    var endAngle = (2.0 * M_PI - M_PI_2)
    // (Next line) ERROR: Extra argument 'radius' in call
    var outerPath : UIBezierPath = UIBezierPath(arcCenter: arcCenter,radius: radius,startAngle: startAngle,endAngle: endAngle,clockwise: true) 

}

我不明白为什么’radius’是一个额外的论据,如果我使用像Apple这样的方法…
你知道怎么解决吗?
谢谢!

解决方法

错误消息非常误导.真正的问题是endAngle:
UIBezierPath(…)的参数具有CGFloat类型,但是您传递了一个
双重论点.显式地转换值有助于:

var endAngle = CGFloat(2.0 * M_PI - M_PI_2)

编译32位体系结构时出现问题,其中CGFloat
被定义为Float而不是Double.

另见https://github.com/ksm/SwiftInFlux:

What is happening here is that CGFloat is a typealias for either Float
or Double depending on whether you’re building for 32 or 64-bits. This
is exactly how Objective-C works,but is problematic in Swift because
Swift doesn’t allow implicit conversions.

We’re aware of this problem and consider it to be serious: we are
evaluating several different solutions right now and will roll one out
in a later beta. As you notice,you can cope with this today by
casting to Double. This is inelegant but effective

(编辑:李大同)

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

    推荐文章
      热点阅读