diff --git a/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift b/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift index 508c6c0..7b558a5 100644 --- a/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift +++ b/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift @@ -37,6 +37,12 @@ extension HomeController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) tabBarController?.tabBar.isHidden = false + restartBannerAutoScroll() + } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + stopBannerAutoScroll() // 화면을 벗어나면 스크롤 중지 } } @@ -128,6 +134,20 @@ extension HomeController { } .disposed(by: disposeBag) } + + private func stopBannerAutoScroll() { + let indexPath = IndexPath(row: 0, section: 0) // 배너 섹션 인덱스 + if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell { + cell.stopAutoScroll() + } + } + + private func restartBannerAutoScroll() { + let indexPath = IndexPath(row: 0, section: 0) + if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell { + cell.startAutoScroll() + } + } } // MARK: - UICollectionViewDelegate, UICollectionViewDataSource diff --git a/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/View/ImageBannerSection/ImageBannerSection/ImageBannerSectionCell.swift b/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/View/ImageBannerSection/ImageBannerSection/ImageBannerSectionCell.swift index c70a9ae..ca96b96 100644 --- a/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/View/ImageBannerSection/ImageBannerSection/ImageBannerSectionCell.swift +++ b/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/View/ImageBannerSection/ImageBannerSection/ImageBannerSectionCell.swift @@ -11,7 +11,7 @@ final class ImageBannerSectionCell: UICollectionViewCell { var disposeBag = DisposeBag() - private var autoScrollTimer: Timer? + private weak var autoScrollTimer: Timer? private lazy var contentCollectionView: UICollectionView = { let view = UICollectionView(frame: .zero, collectionViewLayout: compositionalLayout) @@ -73,10 +73,15 @@ final class ImageBannerSectionCell: UICollectionViewCell { override func prepareForReuse() { super.prepareForReuse() + stopAutoScroll() disposeBag = DisposeBag() isFirstResponseAutoScroll = false } + deinit { + stopAutoScroll() + } + // 자동 스크롤 중지 함수 func stopAutoScroll() { stopButton.isHidden = true