0
ローディングバーを作ろうとしていますが、長い機能を完了するのに数秒かかります。しかし、私はどのくらい機能実行中に私はどのようにUIの変更をトリガするか把握することができるか分からない。以下は私がうまくいくものですが、私は望みのとおりに正確に行動しません。助言がありますか?長いタスクからローディングバーを更新する
func build(_ sender: UIButton) {
let myMutableString = NSMutableAttributedString(string: "Compiling Latest Clean Build", attributes: [NSFontAttributeName: buildLbl.font])
buildLbl.attributedText = myMutableString
let greenStrip = UIView()
greenStrip.backgroundColor = Colors().green
greenStrip.frame = CGRect(x: 0, y: buildStatus.frame.height - 2.5, width: 10, height: 2.5)
buildStatus.addSubview(greenStrip)
UIView.animate(withDuration: 2.0, animations: {
// compile can take a while
compile(structureContent: structuredContent)
greenStrip.frame = CGRect(x: 0, y: self.buildStatus.frame.height - 2.5, width: self.buildStatus.frame.width, height: 2.5)
}, completion: {
(value: Bool) in
greenStrip.removeFromSuperview()
let dvc : PreviewViewController = self.storyboard?.instantiateViewController(withIdentifier: "PreviewViewController") as! PreviewViewController
self.navigationController?.pushViewController(dvc, animated: false)
})
}
私はあなたの長い機能について知っています。あなたの長い機能が何をしているのか、それをどのように実装しているのかを簡単に教えてください。 –
'compile()'関数は主にファイルへの書き込みです。画像や音声も保存しています。それはデータ構造を反復し、ファイルに書き込むか基本的に物事を保存します。 – Antoine