質問編集履歴
1
こードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,277 +1,3 @@
|
|
1
|
-
```
|
2
|
-
|
3
|
-
import UIKit
|
4
|
-
|
5
|
-
import AudioToolbox
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@IBOutlet weak var label: UILabel!
|
14
|
-
|
15
|
-
@IBOutlet weak var pickerView: UIPickerView!
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
//タイマー変数
|
20
|
-
|
21
|
-
var timer = Timer()
|
22
|
-
|
23
|
-
//カウント(経過時間)
|
24
|
-
|
25
|
-
var time = 0
|
26
|
-
|
27
|
-
var timerRunning = false
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
// 選択肢
|
32
|
-
|
33
|
-
var dataList = ["0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
|
34
|
-
|
35
|
-
var dataList2 = ["0", "5","15", "30", "45"]
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
override func viewDidLoad() {
|
40
|
-
|
41
|
-
super.viewDidLoad()
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
54
|
-
|
55
|
-
// 表示する列数
|
56
|
-
|
57
|
-
return 2
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
64
|
-
|
65
|
-
// アイテム表示個数を返す
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if component == 0 {
|
70
|
-
|
71
|
-
// 1個目のピッカーの設定
|
72
|
-
|
73
|
-
return dataList.count
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
return dataList2.count
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
// UIPickerViewDelegate
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
92
|
-
|
93
|
-
// 表示する文字列を返す
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if component == 0 {
|
98
|
-
|
99
|
-
// 1個目のピッカーの設定
|
100
|
-
|
101
|
-
return dataList[row]
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
return dataList2[row]
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
114
|
-
|
115
|
-
// 選択時の処理
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
let minute = dataList[pickerView.selectedRow(inComponent: 0)]
|
120
|
-
|
121
|
-
let second = dataList2[pickerView.selectedRow(inComponent: 1)]
|
122
|
-
|
123
|
-
time = Int(minute)! * 60 + Int(second)!
|
124
|
-
|
125
|
-
print(String(format: "%02d:%02d", minute,second))
|
126
|
-
|
127
|
-
//print("(minute):(second)")
|
128
|
-
|
129
|
-
label.text = "(minute):(second)"
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
@IBOutlet weak var startbtr: UIButton!
|
136
|
-
|
137
|
-
@IBAction func startbutton(_ sender: Any) {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
runTimer()
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
//picker 非表示
|
148
|
-
|
149
|
-
self.startbtr.isHidden = true
|
150
|
-
|
151
|
-
self.stopbtr.isHidden = false
|
152
|
-
|
153
|
-
self.pickerView.isHidden = true
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
func runTimer() {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.letGo),userInfo: nil, repeats: true)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
//タイマーから呼び出されるメソッド
|
176
|
-
|
177
|
-
func letGo(){
|
178
|
-
|
179
|
-
time -= 1
|
180
|
-
|
181
|
-
label.text = "(time / 60):(time % 60)"
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if time <= 0 {
|
186
|
-
|
187
|
-
timer.invalidate()
|
188
|
-
|
189
|
-
label.text = "Finish"
|
190
|
-
|
191
|
-
AudioServicesPlaySystemSound(UInt32(kSystemSoundID_Vibrate))
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
//piker 再表示
|
196
|
-
|
197
|
-
self.startbtr.isHidden = false
|
198
|
-
|
199
|
-
self.pickerView.isHidden = false
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
@IBOutlet weak var stopbtr: UIButton!
|
208
|
-
|
209
|
-
@IBAction func stopbutton(_ sender: Any) {
|
210
|
-
|
211
|
-
timer.invalidate()
|
212
|
-
|
213
|
-
self.startbtr.isHidden = false
|
214
|
-
|
215
|
-
self.stopbtr.isHidden = true
|
216
|
-
|
217
|
-
timerRunning = false
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@IBAction func finishbutton(_ sender: Any) {
|
226
|
-
|
227
|
-
timer.invalidate()
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
let minutes = dataList[pickerView.selectedRow(inComponent: 0)]
|
232
|
-
|
233
|
-
let seconds = dataList2[pickerView.selectedRow(inComponent: 1)]
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
time = Int(minutes)! * 60 + Int(seconds)!
|
238
|
-
|
239
|
-
label.text = "(minutes):(seconds)"
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
//piker 再表示
|
244
|
-
|
245
|
-
self.pickerView.isHidden = false
|
246
|
-
|
247
|
-
self.startbtr.isHidden = false
|
248
|
-
|
249
|
-
self.stopbtr.isHidden = false
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
func vibrate(timer: Timer) {
|
256
|
-
|
257
|
-
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
override func didReceiveMemoryWarning() {
|
264
|
-
|
265
|
-
super.didReceiveMemoryWarning()
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
```
|
274
|
-
|
275
1
|
**やりたいこと**
|
276
2
|
|
277
3
|
カウントダウンしていく中で秒数が一桁になった時でも09,08,07,06のように十の桁に0を残してカウントしたい
|