水平线性进度条,如iOS中的Android

时间:2017-05-29 04:32:20

标签: android ios swift3 progress-bar

如何在iOS中实现水平进度条,如Android。

Progressbar in iOS like Android

我尝试了以下内容,找到了像 deteminate 这样的解决方案。

func startSendPickUpRequestShakeTimer () {

        if self.movingViewTimer == nil {
            self.movingViewTimer =  Timer.scheduledTimer(
                timeInterval: TimeInterval(movingViewSpeed),
                target      : self,
                selector    : #selector(self.startAnimating),
                userInfo    : nil,
                repeats     : true)
        }
}

func startAnimating() {

        let movingViewX = movingView.frame.minX >= view.frame.maxX ? 0-movingView.frame.width-forwardX:movingView.frame.minX + forwardX

        self.movingView.frame = CGRect(x: movingViewX, y: movingView.frame.minY, width: movingView.frame.width, height: moviewViewHeight)

}

但我怎样才能实现其他的,或者有什么好的资源可以做到这一点?

2 个答案:

答案 0 :(得分:0)

我为ios中不确定的进度编写了此扩展名。也许可以帮忙

extension UIProgressView{
    private struct Holder {
        static var _progressFull:Bool = false
        static var _completeLoading:Bool = false;
    }

    var progressFull:Bool {
        get {
            return Holder._progressFull
        }
        set(newValue) {
            Holder._progressFull = newValue
        }
    }

    var completeLoading:Bool {
        get {
            return Holder._completeLoading
        }
        set(newValue) {
            Holder._completeLoading = newValue
        }
    }

    func animateProgress(){
        if(completeLoading){
            return
        }
        UIView.animate(withDuration: 1, animations: {
            self.setProgress(self.progressFull ? 1.0 : 0.0, animated: true)
        })

        progressFull = !progressFull;

        DispatchQueue.main.asyncAfter(deadline: .now() + 1.2) {
            self.animateProgress();
        }
    }

    func startIndefinateProgress(){
        isHidden = false
        completeLoading = false
        animateProgress()
    }

    func stopIndefinateProgress(){
        completeLoading = true
        isHidden = true
    }
}

答案 1 :(得分:0)

这现在是iOS材质组件的一部分。 https://material.io/develop/ios/components/progress-indicators/progress-views

pod 'MaterialComponents/ProgressView'

import MaterialComponents.MaterialProgressView

代码示例:

    let progressView = MDCProgressView()
    progressView.mode = .indeterminate        
    progressView.progressTintColor = .white
    progressView.trackTintColor = UIColor.white.withAlphaComponent(0.2)
    progressView.startAnimating()
    
    view.addSubview(progressView)
    //Then set constraints for your view (I used SnapKit https://github.com/SnapKit/SnapKit)
    progressView.snp.makeConstraints { (make) in
        make.left.equalTo(header.snp.left)
        make.right.equalTo(header.snp.right)
        make.top.equalTo(header.snp.bottom).offset(20)
        make.height.equalTo(4)
    }