Conversation
deleted main storyboard, add windowscene, create app with appropriate folders
add preparation settings
add appLabel/timerLabel
startButton/restartButton/buttonsStackView
add startBt/restartBt/buttonsSV
add work mode and rest mode
work mode rest mode added
add some functionality
add adaptive design
| import SnapKit | ||
|
|
||
| class ViewController: UIViewController, CAAnimationDelegate { | ||
|
|
| let backgroundProgressLayer = CAShapeLayer() | ||
| let animationOfProgressLayer = CABasicAnimation(keyPath: "strokeEnd") | ||
|
|
||
| var timer = Timer() |
| workModeButton.addTarget(self, action: #selector(workModeButtonTapped), for: .touchUpInside) | ||
| return workModeButton | ||
| }() | ||
| private lazy var restModeButton: UIButton = { |
| restModeButton.addTarget(self, action: #selector(restModeButtonTapped), for: .touchUpInside) | ||
| return restModeButton | ||
| }() | ||
| private lazy var appLabel: UILabel = { |
| appLabel.font = UIFont(name: "Marker Felt", size: 30) | ||
| return appLabel | ||
| }() | ||
| private lazy var timerLabel: UILabel = { |
| restartButton.setTitle("Restart", for: .normal) | ||
| restartButton.setTitleColor(.black, for: .normal) | ||
| restartButton.titleLabel?.font = UIFont(name: "Times New Roman", size: 30) | ||
| // restModeButton.backgroundColor = .blue |
| return startButton | ||
| }() | ||
|
|
||
| override func viewDidLoad() { |
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| view.backgroundColor = .white |
There was a problem hiding this comment.
не пишем логику внутри viewdidLoad, тут только вызов методов
There was a problem hiding this comment.
view.backgroundColor = .white
setupHierarchy -> переименуй лучше на setupViews и туда добавь эту настройку
| } | ||
| appLabel.snp.makeConstraints { appLabel in | ||
| appLabel.centerX.equalTo(view) | ||
| appLabel.top.equalTo(view).offset(view.frame.height*0.117) |
There was a problem hiding this comment.
опять magic numbers, след дз не приму работы с магическами цифрами
| } | ||
| } | ||
|
|
||
| internal func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { |
| } | ||
| } | ||
|
|
||
| extension Int { |
There was a problem hiding this comment.
выносим в отдельную папку Foundation+Extensions внутри файл Int+Extensions
| startButton.setTitleColor(.green, for: .normal) | ||
| } | ||
| } | ||
| @objc private func restartButtonTapped() { |
There was a problem hiding this comment.
спейсы не забываем перед методами и свойствами, читать сложно
| timer.invalidate() | ||
| workModeButton.backgroundColor = .gray | ||
| restModeButton.backgroundColor = .white | ||
| time = 25 |
| drawBackgroundLayer() | ||
| } | ||
|
|
||
| @objc private func startButtonTapped() { |
| return String(format: "%02i:%02i", minutes, seconds) | ||
| } | ||
| func drawBackgroundLayer() { | ||
| backgroundProgressLayer.path = UIBezierPath(arcCenter: CGPoint(x: view.frame.midX, y: view.frame.midY), radius: view.frame.width*0.381, startAngle: -90.degreesToRadians, endAngle: 270.degreesToRadians, clockwise: true).cgPath |
There was a problem hiding this comment.
очень длинный
можно в константу отдельную, линия не должна быть больше 120
UIBezierPath(arcCenter: CGPoint(x: view.frame.midX, y: view.frame.midY), radius: view.frame.width*0.381, startAngle: -90.degreesToRadians, endAngle: 270.degreesToRadians, clockwise: true).cgPath
| view.layer.addSublayer(backgroundProgressLayer) | ||
| } | ||
| func drawForegroundLayer() { | ||
| foregroundProgressLayer.path = UIBezierPath(arcCenter: CGPoint(x: view.frame.midX, y: view.frame.midY), radius: view.frame.width*0.381, startAngle: -90.degreesToRadians, endAngle: 270.degreesToRadians, clockwise: true).cgPath |
There was a problem hiding this comment.
здесь тоже самое, очень сложно читать магические числа
https://gist.github.com/mouselangelo/4d8abf2a49cd202773d4e0ba3b0701dd
| foregroundProgressLayer.removeAllAnimations() | ||
| isAnimationStarted = false | ||
| } | ||
| @objc private func workModeButtonTapped() { |
There was a problem hiding this comment.
// MARK: - Actions
все клики лучше вместо собрать и добавить марку
| timerLabel.text = formatTime() | ||
| } | ||
|
|
||
| private func setupHierarchy() { |
| let views = [timerLabel,appLabel,restartButton,startButton,workModeButton,restModeButton] | ||
| views.forEach { view.addSubview($0) } | ||
| } | ||
| private func setupLayout() { |
|
|
||
| setupHierarchy() | ||
| setupLayout() | ||
| drawBackgroundLayer() |
There was a problem hiding this comment.
структура контроллера должна быть такой:
// MARK: UI -> тут у тебя все UI элементы
// MARK: Properties -> тут у тебя все приватные свойства
// MARK: - Lifecycle
// MARK: - SetupViews
// MARK: - Setup Constraints
// MARK: - Actions
а потом все доп хелпер методы
у тебя все методы в разброс
|
салем! дз принято, очень круто сделал progress bar, нужно порабоать над струтурой проекта
|
|
all app logic finished, ready merge to main branch