Skip to content

Commit

Permalink
✨[FEAT] #146 - 북마크한 현상소 나타내는 뷰 스크롤에 따라 애니메이션 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining committed Jan 19, 2023
1 parent b205038 commit c3d58ce
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import Then
final class LikedStudiosViewController: UIViewController {
// MARK: - Properties
var likedStudiosList: [LikedStudio] = []
var lastPanPositionOffset: CGFloat = 0

// MARK: - UI Properties
private let navigationBar = FilinNavigationBar()
private let headerView = UIView()

private let headerView = UIView().then {
$0.backgroundColor = .fillinBlack
}

private lazy var studiosCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()

let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.isScrollEnabled = true
collectionView.backgroundColor = .black
collectionView.backgroundColor = .fillinBlack

return collectionView
}()
Expand Down Expand Up @@ -64,7 +68,7 @@ final class LikedStudiosViewController: UIViewController {

// MARK: - @objc
@objc func upButtonDidTap(_ sender: UIButton) {
studiosCollectionView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
studiosCollectionView.setContentOffset(.zero, animated: true)
}

// MARK: - Custom Method
Expand Down Expand Up @@ -107,6 +111,8 @@ extension LikedStudiosViewController {
layoutHeaderView()
layoutStudiosCollectionView()
layoutFloatingUpButton()
view.bringSubviewToFront(headerView)
view.bringSubviewToFront(navigationBar)
}

private func layoutNavigaionBar() {
Expand Down Expand Up @@ -147,7 +153,7 @@ extension LikedStudiosViewController {
private func layoutStudiosCollectionView() {
view.addSubview(studiosCollectionView)
studiosCollectionView.snp.makeConstraints {
$0.top.equalTo(headerView.snp.bottom)
$0.top.equalTo(navigationBar.snp.bottom)
$0.leading.bottom.trailing.equalToSuperview()
}
}
Expand All @@ -166,6 +172,20 @@ extension LikedStudiosViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// TODO: - 뷰 전환
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
let actualPosition = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
var constantY: CGFloat
if actualPosition.y == lastPanPositionOffset {
constantY = 0
} else {
constantY = actualPosition.y < 0 ? -50 : 0
}
UIView.animate(withDuration: 0.25) {
self.headerView.transform = CGAffineTransform(translationX: 0, y: constantY)
}
lastPanPositionOffset = actualPosition.y
}
}

// MARK: - UICollectionViewDataSource
Expand All @@ -191,4 +211,8 @@ extension LikedStudiosViewController: UICollectionViewDelegateFlowLayout {

return cellSize
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
}
}

0 comments on commit c3d58ce

Please sign in to comment.