Swift 3.0转换错误修复

W.v*_*nus 4 core-graphics cgrect swift3

我有一个快速的2.2项目.现在我将它升级到Swift 3.0但我有一些错误.

open var gridClippingRect: CGRect
{
    var contentRect = viewPortHandler?.contentRect ?? CGRect.zero
    contentRect.insetInPlace(dx: 0.0, dy: -(self.axis?.gridLineWidth ?? 0.0) / 2.0)
    return contentRect
}
Run Code Online (Sandbox Code Playgroud)

错误:'CGRect'类型的值没有成员'insetInPlace'

如何解决这个错误?

rma*_*ddy 9

查看文档CGRect,最接近的方法是insetBy:dx:dy:返回一个新的CGRect.所以下面的代码应该适合你:

contentRect = contentRect.insetBy(dx: 0.0, dy: -(self.axis?.gridLineWidth ?? 0.0) / 2.0)
Run Code Online (Sandbox Code Playgroud)