【发布时间】:2018-04-25 09:29:11
【问题描述】:
我已使用以下代码将UIBezerPath 添加到UIView。
extension CGFloat {
func toRadians() -> CGFloat {//0 360
return self * CGFloat(Double.pi) / 180.0
}
}
override func viewDidAppear(_ animated: Bool) {
let trackLayer = CAShapeLayer()
let circularPath = UIBezierPath(arcCenter: CGPoint(x: arcView.frame.size.width/2,
y: arcView.frame.size.height),
radius: arcView.frame.size.height/2,
startAngle: CGFloat(180.0).toRadians(),
endAngle: CGFloat(0.0).toRadians(),
clockwise: true)
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor.red.cgColor
trackLayer.lineWidth = 3
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapButt
arcView.layer.sublayers?.removeAll()
arcView.layer.addSublayer(trackLayer)
}
但问题是它在顶部提供了额外的不需要的空间,我不需要。我尝试将各种值设置为circularPath,但它没有按需要设置。
【问题讨论】:
-
你最后想要什么?不清楚。
-
跟
arcView的大小有关系吗? -
@Larme 我只想绘制没有多余空间的弧线。在
UIView上,我添加了UIBizerPath,但它考虑了UIView的一半。 -
简单地减少你的 arcView 框架 size.height 必须工作
-
你是说
CGPoint(x: arcView.frame.size.width/2, y: arcView.frame.size.height/2)?我还不清楚你想要什么。如果你的框架更大并且你画了半个圆圈,它会在某个时候有额外的空间。
标签: ios swift uiview uiviewanimation cashapelayer