回答編集履歴
2
変更
answer
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
最近はライブラリを使用する事が多いですが、以前は簡単なクラスを定義して利用していました。
|
2
2
|
見た目にこだわらないのあれば用途的には十分だと思います。
|
3
3
|
|
4
|
+
※コメント頂いた通りSingletonにする必要がなかったのでコードを修正しました。
|
5
|
+
|
4
6
|
```swift
|
5
7
|
// インジケータークラス
|
6
8
|
|
@@ -8,15 +10,10 @@
|
|
8
10
|
|
9
11
|
class IndicatorView: UIView {
|
10
12
|
|
13
|
+
static var Indicator = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
|
11
|
-
static let
|
14
|
+
static let baseView = UIView()
|
12
|
-
let instance = IndicatorView()
|
13
|
-
return instance
|
14
|
-
}()
|
15
15
|
|
16
|
-
var Indicator = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
|
17
|
-
var baseView = UIView()
|
18
|
-
|
19
|
-
func generateBaseView(parentView: UIView) {
|
16
|
+
static func generateBaseView(parentView: UIView) {
|
20
17
|
|
21
18
|
baseView.frame = parentView.bounds
|
22
19
|
baseView.backgroundColor = UIColor.blackColor()
|
@@ -27,15 +24,15 @@
|
|
27
24
|
baseView.addSubview(Indicator)
|
28
25
|
}
|
29
26
|
|
30
|
-
func showIndicator(parentView: UIView?) {
|
27
|
+
static func showIndicator(parentView: UIView?) {
|
31
|
-
|
28
|
+
|
32
29
|
if let parentView = parentView {
|
33
30
|
generateBaseView(parentView)
|
34
31
|
parentView.addSubview(baseView)
|
35
32
|
}
|
36
33
|
}
|
37
34
|
|
38
|
-
func hideIndicator() {
|
35
|
+
static func hideIndicator() {
|
39
36
|
baseView.removeFromSuperview()
|
40
37
|
}
|
41
38
|
}
|
@@ -43,13 +40,13 @@
|
|
43
40
|
|
44
41
|
```swift
|
45
42
|
// 呼び出すところ(NavigationControllerの場合)
|
46
|
-
IndicatorView.
|
43
|
+
IndicatorView.showIndicator(navigationController?.view)
|
47
44
|
|
48
45
|
// 呼び出すところ(ViewControllerの場合)
|
49
|
-
IndicatorView.
|
46
|
+
IndicatorView.showIndicator(view)
|
50
47
|
|
51
48
|
// 消す時
|
52
|
-
IndicatorView.
|
49
|
+
IndicatorView.hideIndicator()
|
53
50
|
```
|
54
51
|
|
55
52
|

|
1
追記
answer
CHANGED
@@ -50,4 +50,6 @@
|
|
50
50
|
|
51
51
|
// 消す時
|
52
52
|
IndicatorView.sharedInstance.hideIndicator()
|
53
|
-
```
|
53
|
+
```
|
54
|
+
|
55
|
+

|