HOME > UIActivityIndicatorView
iOSでローディングをする簡単な方法は標準のインディケータを表示する方法です。画面中央でぐるぐる回ります。
参考:024 UIActivityIndicatorの表示
参考:UIActivityIndicatorView - アクティビティインディケーター
簡単なクラスを作成してみました。これをLoadingProxy.swiftとしてプロジェクトに保存してください。 (上記のサンプルと同じで角丸の視覚でグレー背景で半透明(0.8)のサンプルです。)
import UIKit
struct LoadingProxy{
static var myActivityIndicator: UIActivityIndicatorView!
static func set(v:UIViewController){
self.myActivityIndicator = UIActivityIndicatorView()
self.myActivityIndicator.frame = CGRectMake(0, 0, 50, 50)
self.myActivityIndicator.center = v.view.center
self.myActivityIndicator.hidesWhenStopped = false
self.myActivityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.White
self.myActivityIndicator.backgroundColor = UIColor.grayColor();
self.myActivityIndicator.layer.masksToBounds = true
self.myActivityIndicator.layer.cornerRadius = 5.0;
self.myActivityIndicator.layer.opacity = 0.8;
v.view.addSubview(self.myActivityIndicator);
self.off();
}
static func on(){
myActivityIndicator.startAnimating();
myActivityIndicator.hidden = false;
}
static func off(){
myActivityIndicator.stopAnimating();
myActivityIndicator.hidden = true;
}
}
こちらを追加した状態で、ViewControllerに以下を追加します。
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
LoadingProxy.set(self); //表示する親をセット
LoadingProxy.on();//ローディング表示。非表示にする場合はoff
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
手をこったローディングにこだわらないのならこれでも十分活用できそうです。
2021-05-14 14:21:41 | The pitfalls of Filetransfer in watchconnectivity on WatchOS. And how to avoid.
AppleWatch it succeeds with the actual machine, but if it is a simulator, it will fail、、、
When I... |
2021-05-06 14:04:37 | Line's animation stamp production pitfalls 、、、 failure story
I tried to make a LINE sticker during Golden Week.
I made it and applied, but it was different f... |
2021-04-22 14:54:53 | Cool carousel carefully selected 3 points! Astringent image slider using WebGL.
I was on a trip to find a cool slider yesterday.
It's simple, easy to use, and has a good de... |
Tweet
![]() |
|||
|