From c3d58ce96d591ed19363838d6406214c3c351fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Fri, 20 Jan 2023 03:02:33 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8[FEAT]=20#146=20-=20=EB=B6=81=EB=A7=88?= =?UTF-8?q?=ED=81=AC=ED=95=9C=20=ED=98=84=EC=83=81=EC=86=8C=20=EB=82=98?= =?UTF-8?q?=ED=83=80=EB=82=B4=EB=8A=94=20=EB=B7=B0=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=95=A0=EB=8B=88?= =?UTF-8?q?=EB=A9=94=EC=9D=B4=EC=85=98=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likedStudiosViewController.swift | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Fillin-iOS/Fillin-iOS/Sources/ViewControllers/MyPageViewController/likedStudiosViewController/likedStudiosViewController.swift b/Fillin-iOS/Fillin-iOS/Sources/ViewControllers/MyPageViewController/likedStudiosViewController/likedStudiosViewController.swift index 0ca604d..cfe8142 100644 --- a/Fillin-iOS/Fillin-iOS/Sources/ViewControllers/MyPageViewController/likedStudiosViewController/likedStudiosViewController.swift +++ b/Fillin-iOS/Fillin-iOS/Sources/ViewControllers/MyPageViewController/likedStudiosViewController/likedStudiosViewController.swift @@ -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 }() @@ -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 @@ -107,6 +111,8 @@ extension LikedStudiosViewController { layoutHeaderView() layoutStudiosCollectionView() layoutFloatingUpButton() + view.bringSubviewToFront(headerView) + view.bringSubviewToFront(navigationBar) } private func layoutNavigaionBar() { @@ -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() } } @@ -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 @@ -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) + } }