質問編集履歴
7
文章修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,19 +6,19 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
タイマーが動いてしまわないようにする為にはどのようにしたら良いでしょうか。
|
10
|
+
|
11
|
+
|
12
|
+
|
12
|
-
|
13
|
+
環境
|
13
|
-
|
14
|
-
|
15
|
-
|
16
14
|
|
17
15
|
Xcode 7.1.1
|
18
16
|
|
17
|
+
|
18
|
+
|
19
|
+
使用ライブラリ
|
20
|
+
|
19
|
-
Spring
|
21
|
+
Spring(【よーい】【どん】のアニメーション機能に)
|
20
|
-
|
21
|
-
を使用しています。
|
22
22
|
|
23
23
|
|
24
24
|
|
6
文章修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【Swift】Viewを
|
1
|
+
【Swift】dismissViewControllerAnimatedを使用すると、invalidate()したタイマーが動いてしまう
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
RetryButtonを押し、ゲーム画面(GameViewControllerScene)を再表示すると、
|
1
|
+
一回以上RetryButtonを押し、ゲーム画面(GameViewControllerScene)を再表示すると、
|
2
2
|
|
3
3
|
all Dismiss Buttonを押してスタート画面(ViewControllerScene)を表示した際に、
|
4
4
|
|
5
文章修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,225 +1,233 @@
|
|
1
|
-
RetryButtonを
|
1
|
+
RetryButtonを押し、ゲーム画面(GameViewControllerScene)を再表示すると、
|
2
|
-
|
2
|
+
|
3
|
-
|
3
|
+
all Dismiss Buttonを押してスタート画面(ViewControllerScene)を表示した際に、
|
4
4
|
|
5
5
|
invalidate()したタイマーが作動してしまいます。
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
|
10
|
+
|
9
11
|
Viewを移動してもタイマーを作動させないためにはどのようにしたら良いでしょうか。
|
10
12
|
|
11
13
|
|
12
14
|
|
15
|
+
|
16
|
+
|
17
|
+
Xcode 7.1.1
|
18
|
+
|
19
|
+
Springライブラリ(【よーい】【どん】のアニメーション機能に)
|
20
|
+
|
21
|
+
を使用しています。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
![View構成図](0483e1b54fda0393826ab4bf6f7352b3.png)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```Swift
|
30
|
+
|
31
|
+
// ViewController.swift
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
import UIKit
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class ViewController: UIViewController {
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
override func viewDidLoad() {
|
44
|
+
|
45
|
+
super.viewDidLoad()
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
override func didReceiveMemoryWarning() {
|
54
|
+
|
55
|
+
super.didReceiveMemoryWarning()
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```Swift
|
68
|
+
|
69
|
+
// GameViewController.swift
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
import UIKit
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
class GameViewController: UIViewController {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
@IBOutlet weak var readeyGoLabel: DesignableLabel!
|
82
|
+
|
83
|
+
@IBOutlet weak var timerLabel: UILabel!
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
var cnt: Float = 20.0
|
88
|
+
|
89
|
+
var timer: NSTimer!
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
override func viewDidLoad() {
|
94
|
+
|
95
|
+
super.viewDidLoad()
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
timerLabel.text = "TIME: \(self.cnt)"
|
100
|
+
|
101
|
+
readeyGoLabel.text = ""
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
override func viewDidAppear(animated: Bool) {
|
110
|
+
|
111
|
+
readyGoAnimation()
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
func readyGoAnimation() {
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
readeyGoLabel.text = "よーい"
|
122
|
+
|
123
|
+
readeyGoLabel.animation = "fadeIn"
|
124
|
+
|
125
|
+
readeyGoLabel.curve = "spring"
|
126
|
+
|
127
|
+
readeyGoLabel.duration = 1.4
|
128
|
+
|
129
|
+
readeyGoLabel.animateNext { () -> () in
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
self.readeyGoLabel.text = "どん"
|
134
|
+
|
135
|
+
self.readeyGoLabel.animation = "fadeOut"
|
136
|
+
|
137
|
+
self.readeyGoLabel.curve = "spring"
|
138
|
+
|
139
|
+
self.readeyGoLabel.duration = 0.7
|
140
|
+
|
141
|
+
self.readeyGoLabel.delay = 0.1
|
142
|
+
|
143
|
+
self.readeyGoLabel.animate()
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "countDown:", userInfo: nil, repeats: true)
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
func countDown(timer : NSTimer) {
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
if cnt < 0 {
|
160
|
+
|
161
|
+
timer.invalidate()
|
162
|
+
|
163
|
+
self.timerLabel.text = "TIME: 0.0"
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
} else {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
let str = "TIME: ".stringByAppendingFormat("%.1f",cnt)
|
172
|
+
|
173
|
+
print(str)
|
174
|
+
|
175
|
+
timerLabel.text = str
|
176
|
+
|
177
|
+
cnt -= 0.1
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
override func didReceiveMemoryWarning() {
|
188
|
+
|
189
|
+
super.didReceiveMemoryWarning()
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
@IBAction func retryButtonTapped(sender: AnyObject) {
|
196
|
+
|
197
|
+
timer.invalidate()
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
@IBAction func allDismissButtonTapped(sender: AnyObject) {
|
204
|
+
|
205
|
+
timer.invalidate()
|
206
|
+
|
207
|
+
UIApplication.sharedApplication().keyWindow!.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
補足
|
224
|
+
|
13
225
|
アプリには、主に下記のような機能を実装しています。
|
14
226
|
|
15
|
-
|
227
|
+
- スタート画面(ViewControllerScene)からゲーム画面(GameViewControllerScene)に遷移する。
|
16
|
-
|
228
|
+
|
17
|
-
|
229
|
+
- ゲーム画面に遷移するとfadeInで【よーい】、fadeOutで【どん】と表示される。
|
18
|
-
|
230
|
+
|
19
|
-
|
231
|
+
- NSTimer.scheduledTimerWithTimeIntervalを利用して、20秒のカウントダウンが始まる。
|
20
|
-
|
232
|
+
|
21
|
-
|
233
|
+
- all Dismiss Buttonを押すとスタート画面、RetryButtonを押すと再びゲーム画面が表示される。
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Xcode 7.1.1
|
26
|
-
|
27
|
-
Springライブラリ(【よーい】【どん】のアニメーション機能に)
|
28
|
-
|
29
|
-
を使用しています。
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
![View構成図](0483e1b54fda0393826ab4bf6f7352b3.png)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
```Swift
|
38
|
-
|
39
|
-
// ViewController.swift
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
import UIKit
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
class ViewController: UIViewController {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
override func viewDidLoad() {
|
52
|
-
|
53
|
-
super.viewDidLoad()
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
override func didReceiveMemoryWarning() {
|
62
|
-
|
63
|
-
super.didReceiveMemoryWarning()
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
```
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
```Swift
|
76
|
-
|
77
|
-
// GameViewController.swift
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
import UIKit
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
class GameViewController: UIViewController {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@IBOutlet weak var readeyGoLabel: DesignableLabel!
|
90
|
-
|
91
|
-
@IBOutlet weak var timerLabel: UILabel!
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
var cnt: Float = 20.0
|
96
|
-
|
97
|
-
var timer: NSTimer!
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
override func viewDidLoad() {
|
102
|
-
|
103
|
-
super.viewDidLoad()
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
timerLabel.text = "TIME: \(self.cnt)"
|
108
|
-
|
109
|
-
readeyGoLabel.text = ""
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
override func viewDidAppear(animated: Bool) {
|
118
|
-
|
119
|
-
readyGoAnimation()
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
func readyGoAnimation() {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
readeyGoLabel.text = "よーい"
|
130
|
-
|
131
|
-
readeyGoLabel.animation = "fadeIn"
|
132
|
-
|
133
|
-
readeyGoLabel.curve = "spring"
|
134
|
-
|
135
|
-
readeyGoLabel.duration = 1.4
|
136
|
-
|
137
|
-
readeyGoLabel.animateNext { () -> () in
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
self.readeyGoLabel.text = "どん"
|
142
|
-
|
143
|
-
self.readeyGoLabel.animation = "fadeOut"
|
144
|
-
|
145
|
-
self.readeyGoLabel.curve = "spring"
|
146
|
-
|
147
|
-
self.readeyGoLabel.duration = 0.7
|
148
|
-
|
149
|
-
self.readeyGoLabel.delay = 0.1
|
150
|
-
|
151
|
-
self.readeyGoLabel.animate()
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "countDown:", userInfo: nil, repeats: true)
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
func countDown(timer : NSTimer) {
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
if cnt < 0 {
|
168
|
-
|
169
|
-
timer.invalidate()
|
170
|
-
|
171
|
-
self.timerLabel.text = "TIME: 0.0"
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
} else {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
let str = "TIME: ".stringByAppendingFormat("%.1f",cnt)
|
180
|
-
|
181
|
-
print(str)
|
182
|
-
|
183
|
-
timerLabel.text = str
|
184
|
-
|
185
|
-
cnt -= 0.1
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
override func didReceiveMemoryWarning() {
|
196
|
-
|
197
|
-
super.didReceiveMemoryWarning()
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
@IBAction func retryButtonTapped(sender: AnyObject) {
|
204
|
-
|
205
|
-
timer.invalidate()
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
@IBAction func allDismissButtonTapped(sender: AnyObject) {
|
212
|
-
|
213
|
-
timer.invalidate()
|
214
|
-
|
215
|
-
UIApplication.sharedApplication().keyWindow!.rootViewController?.dismissViewControllerAnimated(true, completion: nil)
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
```
|
4
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,8 +6,6 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
10
|
-
|
11
9
|
Viewを移動してもタイマーを作動させないためにはどのようにしたら良いでしょうか。
|
12
10
|
|
13
11
|
|
@@ -28,7 +26,7 @@
|
|
28
26
|
|
29
27
|
Springライブラリ(【よーい】【どん】のアニメーション機能に)
|
30
28
|
|
31
|
-
使用しています。
|
29
|
+
を使用しています。
|
32
30
|
|
33
31
|
|
34
32
|
|
3
文字修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【Swift】View
|
1
|
+
【Swift】Viewを移動すると、invalidate()したタイマーが動いてしまう
|
test
CHANGED
File without changes
|
2
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
var cnt: Float =
|
97
|
+
var cnt: Float = 20.0
|
98
98
|
|
99
99
|
var timer: NSTimer!
|
100
100
|
|
1
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
Xcode 7.1.1
|
28
28
|
|
29
|
-
Springライブラリ(【よーい】【どん】のアニメーション)
|
29
|
+
Springライブラリ(【よーい】【どん】のアニメーション機能に)
|
30
30
|
|
31
31
|
使用しています。
|
32
32
|
|