1
我有戒備發展觀與alamofire下載時,但問題是,當我想下載警報進度視圖將開始完成,但閃爍,另一個問題是,後面的屏幕將開始成爲褪色黑色我認爲每秒都會顯示一個帶有進度視圖的新警報,並且最後會有很多警報,我該如何避免它們?爲什麼alamofire下載警報的進度會閃爍,後面的屏幕開始變黑?
downloadTimer = Timer.scheduledTimer(timeInterval: 1 , target: self, selector: #selector(flashingDownload), userInfo: nil, repeats: true)
let destination = DownloadRequest.suggestedDownloadDestination()
Alamofire.download("http://example.com", to: destination).downloadProgress(queue: DispatchQueue.global(qos: .utility)) { (progress) in
print("Progress: \(progress.fractionCompleted)")
sixthLevelViewController.progressdownload = Float(progress.fractionCompleted)
if sixthLevelViewController.progressdownload == 1.0 {
self.downloadfinished = true
let alertController = UIAlertController(title: "finish download ", message: " download Completed! ", preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default)
{
(result : UIAlertAction) -> Void in
self.view.isUserInteractionEnabled = true
}
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
alertController.view.tintColor = UIColor.green
alertController.view.backgroundColor = UIColor.green
alertController.view.layer.cornerRadius = 0.1 * alertController.view.bounds.size.width
}
} .validate().responseData { (response) in
print(response.destinationURL!.lastPathComponent)
}
,這裏是定時器
func flashingDownload() {
while (topViewController.presentedViewController != nil){
topViewController = topViewController.presentedViewController!
}
DispatchQueue.main.async {
let alert = UIAlertController(title: "downloading", message: "pls wait", preferredStyle: .alert)
let progressBar = UIProgressView(progressViewStyle: .default)
progressBar.setProgress(sixthLevelViewController.progressdownload, animated: true)
progressBar.frame = CGRect(x: 10, y: 70, width: 250, height: 0)
alert.view.addSubview(progressBar)
self.topViewController.present(alert, animated: false, completion: nil)
if sixthLevelViewController.progressdownload == 1.0 {
print("finished download !")
self.topViewController.dismiss(animated: false , completion: nil)
self.downloadTimer.invalidate()
}
}
代碼正如你在我的代碼看,我認爲控制下載完成另一個變量,所以當進度爲1.0我想關閉提醒