Skip to content

Commit

Permalink
✨ 되감기 기능 수정: 전에 보여주었던 이미지들의 progressView도 하이라이트 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
mingun authored and mingun committed Nov 27, 2023
1 parent 28fb5dd commit c72b403
Showing 1 changed file with 68 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,53 @@ public final class RewindJourneyViewController: UIViewController {

// MARK: - Constants

private enum Metrix {
private enum Metric {

//progress bar
// progress bar
enum Progressbar {
static var height: CGFloat = 4.0
static var inset: CGFloat = 4.0
static var defaultIndex: Int = 0

static let height: CGFloat = 4.0
static let inset: CGFloat = 4.0
static let defaultIndex: Int = 0

}

//stackView
// stackView
enum StackView {
static var inset: CGFloat = 12.0

static let inset: CGFloat = 12.0

}

//musicView
// musicView
enum MusicView {
static var height: CGFloat = 69.0
static var inset: CGFloat = 12.0
static var bottomInset: CGFloat = 34.0

static let height: CGFloat = 69.0
static let inset: CGFloat = 12.0
static let bottomInset: CGFloat = 34.0

}

}

// MARK: - Properties

var stackView = UIStackView()
var presentImageView = UIImageView()
let musicView = MSMusicView()
var progressViews: [MSProgressView]?
var preHighlightenProgressView: MSProgressView?
let leftTouchView = UIButton()
let rightTouchView = UIButton()
private let stackView = UIStackView()
private let presentImageView = UIImageView()
private let musicView = MSMusicView()
private var progressViews: [MSProgressView]?
private var preHighlightenProgressView: MSProgressView?
private let leftTouchView = UIButton()
private let rightTouchView = UIButton()

public var images: [UIImage]?
var presentImageIndex: Int? {
private var presentImageIndex: Int? {
didSet {
guard let index = self.presentImageIndex,
let images else { return }
self.presentImageView.image = images[index]
self.progressViews?[index].isHighlight = true
self.preHighlightenProgressView?.isHighlight = false
self.preHighlightenProgressView = self.progressViews?[index]
self.changeProgressViews()
}
}

// MARK: - UI Components
// MARK: - UI Configuration

func configure() {
self.configureLayout()
Expand All @@ -68,7 +69,7 @@ public final class RewindJourneyViewController: UIViewController {
self.musicView.configure()
}

// MARK: - UI Components: Layout
// MARK: - UI Configuration: Layout

private func configureLayout() {
self.configurePresentImageViewLayout()
Expand All @@ -94,16 +95,17 @@ public final class RewindJourneyViewController: UIViewController {
self.view.addSubview(self.stackView)

self.stackView.axis = .horizontal
self.stackView.spacing = Metrix.Progressbar.inset
self.stackView.spacing = Metric.Progressbar.inset
self.stackView.distribution = .fillEqually

self.stackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.stackView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
self.stackView.heightAnchor.constraint(equalToConstant: Metrix.Progressbar.height),
self.stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: Metrix.StackView.inset),
self.stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -Metrix.StackView.inset)
])
self.stackView.heightAnchor.constraint(equalToConstant: Metric.Progressbar.height),
self.stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,
constant: Metric.StackView.inset),
self.stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,
constant: -Metric.StackView.inset)])
}

private func configureProgressbarsLayout() {
Expand All @@ -123,10 +125,13 @@ public final class RewindJourneyViewController: UIViewController {

self.musicView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.musicView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -Metrix.MusicView.bottomInset),
self.musicView.heightAnchor.constraint(equalToConstant: Metrix.MusicView.height),
self.musicView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: Metrix.MusicView.inset),
self.musicView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -Metrix.MusicView.inset)
self.musicView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor,
constant: -Metric.MusicView.bottomInset),
self.musicView.heightAnchor.constraint(equalToConstant: Metric.MusicView.height),
self.musicView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,
constant: Metric.MusicView.inset),
self.musicView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,
constant: -Metric.MusicView.inset)
])
}

Expand All @@ -148,10 +153,9 @@ public final class RewindJourneyViewController: UIViewController {
])
}

// MARK: - UI Components: Style
// MARK: - UI Configuration: Style

private func configureStyle() {

self.configurePresentImageViewStyle()
self.configureProgressbarsStyle()
}
Expand All @@ -161,10 +165,10 @@ public final class RewindJourneyViewController: UIViewController {
}

private func configureProgressbarsStyle() {
self.presentImageIndex = Metrix.Progressbar.defaultIndex
self.presentImageIndex = Metric.Progressbar.defaultIndex
}

// MARK: - Configure: Action
// MARK: - Configuration: Action

private func configureAction() {
self.configureLeftTouchViewAction()
Expand All @@ -179,6 +183,22 @@ public final class RewindJourneyViewController: UIViewController {
self.rightTouchView.addTarget(self, action: #selector(rightTouchViewTapped), for: .touchUpInside)
}

private func changeProgressViews() {
guard let presentIndex = self.presentImageIndex,
let images else { return }

self.presentImageView.image = images[presentIndex]
self.preHighlightenProgressView = self.progressViews?[presentIndex]
self.preHighlightenProgressView?.isHighlight = false

let minIndex = 0
let maxIndex = images.count - 1

for index in minIndex...maxIndex {
self.progressViews?[index].isHighlight = index <= presentIndex ? true : false
}
}

// MARK: - Life Cycle

public override func viewDidLoad() {
Expand All @@ -187,7 +207,7 @@ public final class RewindJourneyViewController: UIViewController {
self.configure()
}

// MARK: - Functions: Action
// MARK: - Actions

@objc private func leftTouchViewTapped() {
guard let presentImageIndex else {
Expand All @@ -212,9 +232,13 @@ public final class RewindJourneyViewController: UIViewController {
}

// MARK: - Preview

@available(iOS 17, *)
#Preview {
let vc = RewindJourneyViewController()
vc.images = [UIImage(systemName: "pencil")!, UIImage(systemName: "pencil")!, UIImage(systemName: "pencil")!]
return vc
MSFont.registerFonts()
let viewController = RewindJourneyViewController()
viewController.images = [UIImage(systemName: "pencil")!,
UIImage(systemName: "pencil")!,
UIImage(systemName: "pencil")!]
return viewController
}

0 comments on commit c72b403

Please sign in to comment.