小波說雨燕 第三季 構建 swift UI 之 UI組件集-視圖集(七)Progress View視圖 學習筆記

來源:互聯網
上載者:User

標籤:

 

 

 

 

 1 import UIKit 2  3 class ViewController: UIViewController{ 4      5     @IBOutlet weak var progress: UIProgressView! 6      7     let operationQueue = NSOperationQueue() 8      9     var 完成進度: Int = 0{10         didSet(oldValue){11             let 進度比 = Float(完成進度)/Float(100)12             let 是否動畫 = (oldValue != 0)13             progress.setProgress(進度比, animated: 是否動畫)14         }15     }16     //類比一個進度“睡眠操作”17     func simulateProgress(){18         for _ in 0...100 {19             operationQueue.addOperationWithBlock{20             //將系統時間延遲隨機的秒,類比其他程式其他功能的操作21             sleep(arc4random_uniform(10))22             23             NSOperationQueue.mainQueue().addOperationWithBlock{24                 self.完成進度++25                 return26             }27             }28         }29     }30     override func viewDidLoad() {31         super.viewDidLoad()32         simulateProgress()33         34     }35 36     override func didReceiveMemoryWarning() {37         super.didReceiveMemoryWarning()38     }39 }

 

 

小波說雨燕 第三季 構建 swift UI 之 UI組件集-視圖集(七)Progress View視圖 學習筆記

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.