質問編集履歴
2
訂正箇所>コードをマークダウンで表示
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,6 +44,8 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
+
```swift
|
48
|
+
|
47
49
|
import UIKit
|
48
50
|
|
49
51
|
import AudioToolbox
|
@@ -301,3 +303,5 @@
|
|
301
303
|
|
302
304
|
|
303
305
|
}
|
306
|
+
|
307
|
+
```
|
1
コードを追加してみました。こんな感じで良いでしょうか?
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,3 +37,267 @@
|
|
37
37
|
![![Q1の時はFullScreenで表示されるのですが](73d5b15a4769807865f22ce299552736.png)](b77f3925710f90008b46321577880e4d.png)!
|
38
38
|
|
39
39
|
[Q2以降FullScreenではなくなります。Q2以降もFUllScreenで表示する方法はありますか?](b0055d0805f85c4d4167888a97b31f0a.png)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
import UIKit
|
48
|
+
|
49
|
+
import AudioToolbox
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
class HistoryQuestionViewController: UIViewController {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
var questionData: HistoryQuestionData!
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
@IBOutlet weak var questionNoLabel: UILabel!
|
68
|
+
|
69
|
+
@IBOutlet weak var questionTextView: UITextView!
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
@IBOutlet weak var answer1Button: UIButton!
|
74
|
+
|
75
|
+
@IBOutlet weak var answer2Button: UIButton!
|
76
|
+
|
77
|
+
@IBOutlet weak var answer3Button: UIButton!
|
78
|
+
|
79
|
+
@IBOutlet weak var answer4Button: UIButton!
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
@IBOutlet weak var correctImageView: UIImageView!
|
86
|
+
|
87
|
+
@IBOutlet weak var IncorrectImageView: UIImageView!
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
@IBOutlet weak var goToTitle: UIButton!
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
override func viewDidLoad() {
|
98
|
+
|
99
|
+
super.viewDidLoad()
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// Do any additional setup after loading the view.
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
//初期データ設定処理。全画面で設定済みのquestionDataから値を取り出す。
|
110
|
+
|
111
|
+
questionNoLabel.text = "Q(questionData.questionNo)"
|
112
|
+
|
113
|
+
questionTextView.text = questionData.question
|
114
|
+
|
115
|
+
answer1Button.setTitle(questionData.answer1, for: UIControl.State.normal)
|
116
|
+
|
117
|
+
answer2Button.setTitle(questionData.answer2, for: UIControl.State.normal)
|
118
|
+
|
119
|
+
answer3Button.setTitle(questionData.answer3, for: UIControl.State.normal)
|
120
|
+
|
121
|
+
answer4Button.setTitle(questionData.answer4, for: UIControl.State.normal)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
@IBAction func tapAnswer1Button(_ sender: Any) {
|
130
|
+
|
131
|
+
questionData.userChoiceAnswerNumber = 1
|
132
|
+
|
133
|
+
goNextQuestionWithAnimation()
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
@IBAction func tapAnswer2Button(_ sender: Any) {
|
140
|
+
|
141
|
+
questionData.userChoiceAnswerNumber = 2
|
142
|
+
|
143
|
+
goNextQuestionWithAnimation()
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
@IBAction func tapAnswer3Button(_ sender: Any) {
|
150
|
+
|
151
|
+
questionData.userChoiceAnswerNumber = 3
|
152
|
+
|
153
|
+
goNextQuestionWithAnimation()
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
@IBAction func tapAnswer4Button(_ sender: Any) {
|
160
|
+
|
161
|
+
questionData.userChoiceAnswerNumber = 4
|
162
|
+
|
163
|
+
goNextQuestionWithAnimation()
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//次の問題にアニメーション付きで進む
|
170
|
+
|
171
|
+
func goNextQuestionWithAnimation() {
|
172
|
+
|
173
|
+
//正解しているか判定する
|
174
|
+
|
175
|
+
if questionData.isCorrect() {
|
176
|
+
|
177
|
+
//正解のアニメーションを再生しながら次の問題へ遷移する
|
178
|
+
|
179
|
+
goNextQuestionWithCorrectAnimation()
|
180
|
+
|
181
|
+
} else {
|
182
|
+
|
183
|
+
//不正解のアニメーションを再生しながら次の問題へ遷移する。
|
184
|
+
|
185
|
+
goNextQuestionWithIncorrectAnimation()
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
//次の問題に正解のアニメーション付きで遷移する
|
196
|
+
|
197
|
+
func goNextQuestionWithCorrectAnimation() {
|
198
|
+
|
199
|
+
//正解を伝える音を鳴らす
|
200
|
+
|
201
|
+
AudioServicesPlayAlertSound(1025)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
//アニメーション
|
206
|
+
|
207
|
+
UIView.animate(withDuration: 1.0, animations: {
|
208
|
+
|
209
|
+
//アルファ値を1.0に変化させる(初期値はStoryboardで0.0に設定ずみ)
|
210
|
+
|
211
|
+
self.correctImageView.alpha = 1.0
|
212
|
+
|
213
|
+
}) {
|
214
|
+
|
215
|
+
(Bool) in self.goNextQuestion() //アニメーション完了後に次の問題に進む
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
//次の問題に不正解のアニメーション付きでする
|
226
|
+
|
227
|
+
func goNextQuestionWithIncorrectAnimation() {
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
//不正解を伝える音を鳴らす
|
232
|
+
|
233
|
+
AudioServicesPlayAlertSound(1006)
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
//アニメーション
|
238
|
+
|
239
|
+
UIView.animate(withDuration: 1.0, animations: {
|
240
|
+
|
241
|
+
//アルファ値を1.0に変化させる(初期値はStoryboardで0.0に設定ずみ)
|
242
|
+
|
243
|
+
self.IncorrectImageView.alpha = 1.0
|
244
|
+
|
245
|
+
}) {
|
246
|
+
|
247
|
+
(Bool) in self.goNextQuestion() //アニメーション完了後に次の問題に進む
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
func goNextQuestion() {
|
258
|
+
|
259
|
+
//問題文の取り出し
|
260
|
+
|
261
|
+
guard let nextQuestion = HistoryQuestionDataManager.sharedInstance.nextQuestion() else {
|
262
|
+
|
263
|
+
//問題文がなければ結果画面へ遷移する
|
264
|
+
|
265
|
+
//StoryboardのIdentifierに設定した値(result)を指定して
|
266
|
+
|
267
|
+
//ViewControllerを生成する
|
268
|
+
|
269
|
+
if let resultViewController = storyboard?.instantiateViewController(withIdentifier: "historyResult") as? HistoryResultViewController {
|
270
|
+
|
271
|
+
//Storyboardのsegueを利用しない明示的な画面遷移処理
|
272
|
+
|
273
|
+
present(resultViewController, animated: true, completion: nil)
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
return
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if let nextQuestionViewController =
|
284
|
+
|
285
|
+
storyboard?.instantiateViewController(withIdentifier: "historyQuestion")
|
286
|
+
|
287
|
+
as? HistoryQuestionViewController {
|
288
|
+
|
289
|
+
nextQuestionViewController.questionData = nextQuestion
|
290
|
+
|
291
|
+
present(nextQuestionViewController, animated: true,
|
292
|
+
|
293
|
+
completion: nil)
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
}
|