gpt4 book ai didi

swift - 我正在使用 UIBezierPath 制作一个循环进度条程序,这是一个好的做法吗?

转载 作者:行者123 更新时间:2023-11-30 12:19:05 25 4
gpt4 key购买 nike

获取 View roundView 并将其设为圆形,然后沿 roundView 绘制圆形路径,并在时间方法中给出起始笔划和结束笔划。这是正确的做法

    var count = 0.0
var circlePath: UIBezierPath!
var roundView: UIView!
var circleShape: CAShapeLayer!
var x: Timer!
var headerView: HeaderView!
override func viewDidLoad() {
super.viewDidLoad()
// setup()
roundView = UIView(frame: CGRect(x: 100, y: 100, width: 300, height: 300))
roundView.addSubview(label)
label.centerXAnchor.constraint(equalTo: roundView.centerXAnchor).isActive = true
label.centerYAnchor.constraint(equalTo: roundView.centerYAnchor).isActive = true
roundView.layer.cornerRadius = roundView.frame.size.width / 2

// bezier path
circlePath = UIBezierPath(arcCenter: CGPoint (x: roundView.frame.size.width / 2, y: roundView.frame.size.height / 2),
radius: roundView.frame.size.width / 2,
startAngle: CGFloat(-0.5 * Double.pi),
endAngle: CGFloat(1.5 * Double.pi),
clockwise: true)
// circle shape
circleShape = CAShapeLayer()
circleShape.path = circlePath.cgPath
circleShape.borderWidth = 10
circleShape.strokeColor = UIColor.blue.cgColor
circleShape.fillColor = UIColor.clear.cgColor
circleShape.lineWidth = 10
// set start and end values
circleShape.strokeStart = 0.0
x = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(self.update), userInfo: nil, repeats: true)


}

添加结束描边

@objc func update() {
// Something cool
if count >= 1{
x.invalidate()

}
count = count + 0.01
self.label.text = String(Int(count * 100))
circleShape.strokeEnd = CGFloat(count)
roundView.layer.addSublayer(circleShape)
// add subview
self.tableView.addSubview(roundView)
print(count)
}

最佳答案

当我们谈论好的或坏的实践时,通常意味着该方法是否有效、安全。假设强制展开是一种不好的做法,而使用 if let 是一种好的做法。

在您的情况下,圆形进度条只不过是顶部有某个图层或路径的 View ,最终形成了类似条的 View 。这是正确的做法,而且并不是一个坏习惯。

关于swift - 我正在使用 UIBezierPath 制作一个循环进度条程序,这是一个好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45029449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com