Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

박스오피스II [STEP 2] Erick, kyungmin #105

Open
wants to merge 24 commits into
base: ic_9_kyungmin
Choose a base branch
from

Conversation

YaRkyungmin
Copy link

@July911
안녕하세요 July!!
리뷰이 Erick🐶, Kyungmin🐼 입니다!
박스오피스II의 두번째 스탭입니다!
이번에도 많은 조언 부탁드립니다🙇


🤔 고민했던 점

1️⃣ 화면 모드 변경

alert의 버튼을 눌렀을 때 CollectionViewlayoutcell을 어떻게 바꿀지 고민했습니다.
CollectionViewMode라는 열거형을 만들어 Controller가 프로퍼티로 열거형 인스턴스를 들고 있고 collectionViewMode를 분기처리하여 layoutcell을 결정하도록 설정했습니다.

CollectionViewMode 코드

private enum CollectionViewMode {
    case list
    case grid
}

dataSource 코드

UICollectionViewDiffableDataSource<Section, DailyBoxOffice>(collectionView: collectionView) { collectionView, indexPath, dailyBoxOffice in
    switch self.collectionViewMode {
    case .list:
        // ...

        return listCell
    case .grid:
        // ...

        return gridCell
    }
}

2️⃣ 모드 변경 애니메이션

처음에는 모드 변경을 할 때 collectionView.reloadData()로 모든 셀을 다시 로드하였습니다. 하지만 이럴 경우 애니메이션 효과 없이 화면이 한번에 바뀌어 사용자 경험을 저하시킬 수 있기에 setCollectionViewLayoutreloadSections을 사용하여 layout이 바뀌는 순간과 section이 리로드 되는 순간에 애니메이션 효과를 주었습니다.

layout이 업데이트 될 때 애니메이션

switch collectionViewMode {
case .list:
    collectionView.setCollectionViewLayout(listLayout(), animated: true)
case .grid:
    collectionView.setCollectionViewLayout(gridLayout(), animated: true)
}

reloadSections와 apply를 사용하여 section이 업데이트 될 때 애니메이션

var snapshot = NSDiffableDataSourceSnapshot<Section, DailyBoxOffice>()
snapshot.appendSections([.main])
snapshot.appendItems(boxOfficeManager.dailyBoxOffices, toSection: .main)
snapshot.reloadSections([.main])

dailyBoxOfficeDataSource.apply(snapshot, animatingDifferences: true)

3️⃣ dynamic하게 cell의 높이를 변경하기

처음 label들의 text에만 adjustsFontForContentSizeCategory속성을 true로 변경해줬을때는 collectionViewcell높이가 dynamic하게 변경되지 않았습니다.
centerY로 설정돼있던 label들의 제약을 topAnchorbottomAnchorcontentViewtopAnchorbottomAnchor를 잇고, .estimated를 활용해 dynamic하게 cell의 높이가 변경 되게 해줬습니다.

let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                      heightDimension: .estimated(80))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), 
                                       heightDimension: .estimated(80))

🙇‍♂️ 조언을 얻고싶은 점

1️⃣ 영화 상세화면 dynamic type 적용

요구사항에서는 dynamic type을 적용했을때 감독, 제작년도, 개봉일 등의 titleLabel이 크기가 커져서 모두 같은 크기를 갖는 것처럼 보였습니다. titleLabelCompression priority.required로 설정하는 방법이 제일 바람직하다고 판단하여 적용했지만, 세로 줄이 요구사항과는 다르게 맞지 않았습니다.

이를 해결하기 위해 titleLabel과 오른쪽 정보를 닮는 label을 각각 다른 세로 스택뷰에 따로 담아서 해결하려 했으나 오른쪽 정보를 닮는 label크기가 유동적이기때문에 이 방법으로도 해결하지 못했습니다.

미리 titleLabel의 크기를 고정시켜놓는 방법 이외에 이 문제를 어떻게 해결할 수 있을까요?

📃 요구사항 화면

🔨 현재 구현된 화면


📚 참고 링크

@@ -10,6 +10,7 @@ import UIKit
final class BoxOfficeViewController: UIViewController {
private let boxOfficeManager: BoxOfficeManager
private var collectionView: UICollectionView!
private var collectionViewMode: CollectionViewMode = .list
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주입을 받아보는건 어떨까요 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주입시켜줬습니다:)

@@ -117,32 +144,87 @@ extension BoxOfficeViewController {
return
}
}

@objc private func didTapChangeViewModeButton() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

collectionView.delegate = self
}

private func setupCollectionViewLayout() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인자로 안받고 이렇게 하신 이유가 있을까요 ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UICollectionViewDiffableDataSource 코드에서 분기처리를 한 것과 같이 collectionViewMode 프로퍼티를 이용하여 분기처리를 하려고 했었습니다!
UICollectionViewLayout을 인자로 받으면 코드가 더욱 간단해지기 때문에 인자로 받도록 변경하였습니다!

var snapshot = NSDiffableDataSourceSnapshot<Section, DailyBoxOffice>()
snapshot.appendSections([.main])
snapshot.appendItems(boxOfficeManager.dailyBoxOffices, toSection: .main)
snapshot.reloadSections([.main])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snapshot.reloadSections([.main])
이건 왜 필요한건가요 ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reloadSections(_:)snapshot의 지정된 섹션 내에서 데이터를 다시 로드하는 메서드입니다.
reloadSections를 하지 않으면 바뀐 데이터가 없어 apply를 하여도 셀이 바뀌지 않기 때문에 reloadSectionsmain 섹션의 데이터를 리로드하여 새로운 셀이 사용될 수 있도록 하였습니다!

@@ -236,3 +332,11 @@ extension BoxOfficeViewController {
case main
}
}

// MARK: CollectionView Mode
extension BoxOfficeViewController {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주입을 받을게 아니라면, private이여도 될 것 같네요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주입을 받는 방식으로 바꿔줬기 때문에 private은 해주지 않았습니다☺️


let rankStateColor = dailyBoxOffice.rankStateColor

rankChangeLabel.convertColor(target: rankStateColor.targetString, as: rankStateColor.color)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨벤션이 다른 메서드랑은 좀 다르네요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func setupLabels(_ dailyBoxOffice: DailyBoxOffice) {
        let rankStateColor = dailyBoxOffice.rankStateColor
        rankLabel.text = dailyBoxOffice.rank
        rankChangeLabel.text = dailyBoxOffice.rankState
        movieTitleLabel.text = dailyBoxOffice.movieTitle
        audienceCountLabel.text = dailyBoxOffice.dailyAndTotalAudience
        
        rankChangeLabel.convertColor(target: rankStateColor.targetString, as: rankStateColor.color)
    }

다음과 같이 컨벤션 수정했습니다😆

}

private func setupContentView() {
contentView.layer.cornerRadius = 4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layer를 쓰셔서 질문드립니다.
MasksToBounds 는 뭘까요 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

masksToBoundslayerBool 프로퍼티입니다.
true일때는 서브뷰들이 테두리를 기준으로 잘리게 되고, false일때는 잘리지 않게 됩니다.
기본값이 false이기 때문에 true로 변경해줬습니다☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants