From 9d9ec9ad75d8a2236407680628b0d5f5fa40f4c3 Mon Sep 17 00:00:00 2001 From: 0Hooni Date: Thu, 30 Oct 2025 02:46:54 +0900 Subject: [PATCH] =?UTF-8?q?fix/#180:=20Timer=EA=B0=80=20=EA=B3=84=EC=86=8D?= =?UTF-8?q?=20=EB=A9=94=EB=AA=A8=EB=A6=AC=EC=97=90=20=EB=82=A8=EC=95=84=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Timer 자체를 약한 참조로 수정 - reuse시 타이머 정지 - 홈 화면의 뷰 사이클에 맞춰 타이머 시작/정지 --- .../Scene/Home/Main/HomeController.swift | 20 +++++++++++++++++++ .../ImageBannerSectionCell.swift | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift b/Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift index 508c6c07..7b558a58 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 c70a9aea..ca96b969 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