将 CGPathAddArcToPoint 转换为 Swift 3
convert CGPathAddArcToPoint to Swift 3
我升级到 Swift 3,但我很难在网上找到修复此问题的提示。我能够研究移动并添加一行但不是这个。
CGPathAddArcToPoint(bubblePath, nil,
bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y,
bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+self.cornerRadius,
self.cornerRadius)
这是我的原始代码,但我不知道如何转换它。我很确定我需要使用 addArc 但这就是我研究的范围。
有人可以帮我吗?
This is now a method and not a loose global function ,所以您需要执行此操作的方式应该类似于:
let bubblePath = CGMutablePath.init()
let point1 = CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y)
let point2 = CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+self.cornerRadius)
bubblePath.addArc(tangent1End: point1, tangent2End: point2, radius: self.cornerRadius)
那个 Swift(3 及更高版本)的替代品是 addArc(tangent1End:tangent2End:radius:transform:)
。
你可以像这样使用它(为了简洁起见,也可以在 CGRect
上使用其他一些方便的 Swift API):
bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.maxX, y: bubbleRect.minY)
tangent2End: CGPoint(x: bubbleRect.maxX, y: bubbleRect.minY + self.cornerRadius),
radius: self.cornerRadius)
(请注意 transform
参数的默认值为 .identity
,因此如果您将 nil
与 global-function版本。)
我升级到 Swift 3,但我很难在网上找到修复此问题的提示。我能够研究移动并添加一行但不是这个。
CGPathAddArcToPoint(bubblePath, nil,
bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y,
bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+self.cornerRadius,
self.cornerRadius)
这是我的原始代码,但我不知道如何转换它。我很确定我需要使用 addArc 但这就是我研究的范围。
有人可以帮我吗?
This is now a method and not a loose global function
let bubblePath = CGMutablePath.init()
let point1 = CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y)
let point2 = CGPoint(x: bubbleRect.origin.x+bubbleRect.size.width, y: bubbleRect.origin.y+self.cornerRadius)
bubblePath.addArc(tangent1End: point1, tangent2End: point2, radius: self.cornerRadius)
那个 Swift(3 及更高版本)的替代品是 addArc(tangent1End:tangent2End:radius:transform:)
。
你可以像这样使用它(为了简洁起见,也可以在 CGRect
上使用其他一些方便的 Swift API):
bubblePath.addArc(tangent1End: CGPoint(x: bubbleRect.maxX, y: bubbleRect.minY)
tangent2End: CGPoint(x: bubbleRect.maxX, y: bubbleRect.minY + self.cornerRadius),
radius: self.cornerRadius)
(请注意 transform
参数的默认值为 .identity
,因此如果您将 nil
与 global-function版本。)