Skip to content

Commit

Permalink
[Feat/#28] Onboarding - progressView 역방향 애니매이션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-seonwoo committed Jan 8, 2024
1 parent 4b7d265 commit 4a366a6
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import SnapKit
import Then

final class OnboardingProgressView: UIProgressView {
private var progressAmount: Int = 0
var progressAmount: Int = 0 {
didSet {
if oldValue > progressAmount {
removeProgressBar()
} else {
addProgressBar()
}
}
}

init(progressAmount: Int) {
init() {
super.init(frame: .zero)
self.progressAmount = progressAmount

configureProgressView()
setConstraints()
Expand All @@ -27,7 +34,7 @@ final class OnboardingProgressView: UIProgressView {

private func setConstraints() {
self.snp.makeConstraints {
$0.height.equalTo(4.adjustedHeight)
$0.height.equalTo(4.adjusted)
}
}

Expand All @@ -38,14 +45,29 @@ final class OnboardingProgressView: UIProgressView {
}
}

func setProgressBar() {
self.setProgress(Float(self.progressAmount - 1) / 6.0, animated: false)

private func addProgressBar() {
let startValue = Float(max(0, self.progressAmount - 1)) / 6.0
let endValue = Float(self.progressAmount) / 6.0

self.setProgress(startValue, animated: false)

DispatchQueue.main.async() {
UIView.animate(withDuration: 0.5, delay: 0, options: [.beginFromCurrentState, .allowUserInteraction], animations: { [unowned self] in
self.setProgress(Float(self.progressAmount) / 6.0, animated: true)
self.setProgress(endValue, animated: true)
})
}
}
}

private func removeProgressBar() {
let startValue = Float(min(6, self.progressAmount + 1)) / 6.0
let endValue = Float(self.progressAmount) / 6.0

self.setProgress(startValue, animated: false)

DispatchQueue.main.async() {
UIView.animate(withDuration: 0.5, delay: 0, options: [.beginFromCurrentState, .allowUserInteraction], animations: { [unowned self] in
self.setProgress(endValue, animated: true)
})
}
}
}

0 comments on commit 4a366a6

Please sign in to comment.