Skip to content

Commit 899a91f

Browse files
committed
Edited the button animation.
1 parent 1dea6a4 commit 899a91f

File tree

8 files changed

+62
-55
lines changed

8 files changed

+62
-55
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Pods/.DS_Store

0 Bytes
Binary file not shown.

Pods/Target Support Files/.DS_Store

0 Bytes
Binary file not shown.

TimerApp/.DS_Store

0 Bytes
Binary file not shown.

TimerApp/Assets.xcassets/.DS_Store

0 Bytes
Binary file not shown.

TimerApp/ExtensionViewController.swift

+47-31
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,50 @@
77

88
import UIKit
99

10-
extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {
11-
12-
func setAlert() {
13-
let alert = UIAlertController(title: "Время истекло!", message: nil, preferredStyle: .alert)
14-
15-
let alertAction = UIAlertAction(title: "ОК", style: .cancel) { _ in
16-
print("Готово")
17-
}
18-
19-
alert.addAction(alertAction)
20-
present(alert, animated: true)
21-
}
22-
23-
func numberOfComponents(in pickerView: UIPickerView) -> Int {
24-
return 1
25-
}
26-
27-
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
28-
return time.count
29-
30-
}
31-
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
32-
let currentTime = String(time[row])
33-
return currentTime
34-
}
35-
36-
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
37-
let currentTime = String(time[row])
38-
timerLabel.text = currentTime
39-
}
40-
}
10+
extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource {
11+
12+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
13+
return 3
14+
}
15+
16+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
17+
switch component {
18+
case 0:
19+
return 25
20+
case 1, 2:
21+
return 60
22+
default:
23+
return 0
24+
}
25+
}
26+
27+
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
28+
return pickerView.frame.size.width/3
29+
}
30+
31+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
32+
switch component {
33+
case 0:
34+
return "\(row) Hour"
35+
case 1:
36+
return "\(row) Minute"
37+
case 2:
38+
return "\(row) Second"
39+
default:
40+
return ""
41+
}
42+
}
43+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
44+
switch component {
45+
case 0:
46+
hour = row
47+
case 1:
48+
minutes = row
49+
case 2:
50+
seconds = row
51+
default:
52+
break;
53+
}
54+
}
55+
}
56+

TimerApp/ViewController.swift

+15-24
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ class ViewController: UIViewController {
4444

4545
return imageView
4646
}()
47-
48-
let time: [Int] = {
49-
var time = [Int]()
50-
for sec in 1...60 {
51-
time += [sec]
52-
}
53-
return time
54-
}()
55-
56-
let hours: [Int] = {
57-
var time = [Int]()
58-
for sec in 0...23 {
59-
time += [sec]
60-
}
61-
return time
62-
}()
63-
6447
let shapeLayer: CAShapeLayer = {
6548
let layer = CAShapeLayer()
6649
return layer
@@ -76,8 +59,10 @@ class ViewController: UIViewController {
7659
return button
7760
}()
7861

62+
var hour: Int = 0
63+
var minutes: Int = 0
64+
var seconds: Int = 0
7965
var timer = Timer()
80-
8166
var durationTimer = 10
8267

8368
override func viewDidLoad() {
@@ -97,7 +82,7 @@ class ViewController: UIViewController {
9782
self.animationCircular()
9883
startButton.animation = "fadeIn"
9984
startButton.delay = 0.3
100-
startButton.duration = 1
85+
startButton.duration = 2
10186
startButton.animate()
10287
}
10388
}
@@ -127,7 +112,7 @@ extension ViewController {
127112
self.startButton.isHidden = false
128113
startButton.animation = "squeezeUp"
129114
startButton.delay = 0.3
130-
startButton.duration = 1
115+
startButton.duration = 2.2
131116
AudioServicesPlaySystemSound(1000)
132117
startButton.animate()
133118
}
@@ -218,17 +203,13 @@ extension ViewController {
218203
@objc func editValueTimer() {
219204
print("Tap")
220205
let picker = UIPickerView()
221-
picker.tintColor = .black
222206
picker.delegate = self
223207
picker.dataSource = self
224-
225208
let toolbar = UIToolbar()
226209
toolbar.sizeToFit()
227210
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: .none, action: #selector(pressDone))
228211
toolbar.setItems([.flexibleSpace(), doneButton,], animated: true)
229212
textField.inputAccessoryView = toolbar
230-
231-
textField.delegate = self
232213
textField.isHidden = true
233214
secondView.addSubview(textField)
234215
textField.inputView = picker
@@ -238,6 +219,16 @@ extension ViewController {
238219
@objc func pressDone() {
239220
self.view.endEditing(true)
240221
}
222+
private func setAlert() {
223+
let alert = UIAlertController(title: "Время истекло!", message: nil, preferredStyle: .alert)
224+
225+
let alertAction = UIAlertAction(title: "ОК", style: .cancel) { _ in
226+
print("Готово")
227+
}
228+
229+
alert.addAction(alertAction)
230+
present(alert, animated: true)
231+
}
241232
}
242233

243234

0 commit comments

Comments
 (0)