swift UIProgressView在setProgress中通过animated = true变为透明

i34xakig  于 2023-08-02  发布在  Swift
关注(0)|答案(3)|浏览(124)

在iOS15中,UIProgressView更改了行为。当我使用self.progress.setProgress(1.0, animated: true)时,它从透明样式开始。如何返回到“alpha = 1”样式。

  1. progress = 0
  2. progress = 20%
  3. progress = 70%
  4. progress = 90%
    P.S.:progress.alpha = 1 does not work
46scxncf

46scxncf1#

改变这种不透明/透明行为的唯一方法是使用您自己的计时器。

private let progressUnit = Progress(totalUnitCount: 20)

func startAnimate(){
        self.progressView.setProgress(0.0, animated: false)
        self.progressUnit.completedUnitCount = 0
        
        Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
            guard self.progressUnit.isFinished == false else{
                timer.invalidate()
                return
            }
            
            self.progressUnit.completedUnitCount += 1
            let progressFloat = Float(self.progressUnit.fractionCompleted)
            self.progressView.setProgress(progressFloat, animated: true)
        }
    }

字符串

bvjxkvbb

bvjxkvbb2#

使用带有颜色的UIImage扩展设置tintImage可以工作。这似乎是我消除这种透明度的最简单方法。

progressView.progressImage = UIImage(color: progressTintColor)

字符串
UIImage扩展

extension UIImage {
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
    let rect = CGRect(origin: .zero, size: size)
    UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
    color.setFill()
    UIRectFill(rect)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    
    guard let cgImage = image?.cgImage else { return nil }
    self.init(cgImage: cgImage)
} }

v1uwarro

v1uwarro3#

属性progressImagetrackImage它在以前的iOS版本上运行良好

相关问题