From 56a45bf2d8b848029d2a381dabcef940e3e5da5f Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 20:41:00 +0900 Subject: [PATCH 01/11] =?UTF-8?q?refactor:=20ZoomedImageViewController=20?= =?UTF-8?q?=EB=8B=A8=EC=9D=BC=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=EB=A1=9C=20=EB=8B=A8=EC=88=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subviews/ZoomingCollectionView.swift | 101 ---------- .../Subviews/ZoomingCollectionViewCell.swift | 85 -------- .../ZoomedImageViewController.swift | 184 ++++++------------ koin.xcodeproj/project.pbxproj | 16 -- 4 files changed, 57 insertions(+), 329 deletions(-) delete mode 100644 Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift delete mode 100644 Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift deleted file mode 100644 index 009d00b89..000000000 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift +++ /dev/null @@ -1,101 +0,0 @@ -// -// ZoomingCollectionView.swift -// koin -// -// Created by 홍기정 on 4/22/26. -// - -import UIKit -import Combine - -final class ZoomingCollectionView: UICollectionView { - - private var images: [UIImage?] = [] - let closeButtonPublisher = PassthroughSubject() - - var imageCount: Int { - images.count - } - - init() { - let layout = UICollectionViewFlowLayout() - layout.scrollDirection = .horizontal - layout.minimumLineSpacing = 0 - layout.minimumInteritemSpacing = 0 - - super.init(frame: .zero, collectionViewLayout: layout) - setUpCollectionView() - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func setImages(_ newImages: [UIImage?]) { - images = newImages - reloadData() - setContentOffset(.zero, animated: false) - } - - func setImage(_ newImage: UIImage?) { - setImages([newImage]) - } - - func showImage(at index: Int, animated: Bool) { - guard 0.. Int { - images.count - } - - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell( - withReuseIdentifier: ZoomingCollectionViewCell.identifier, - for: indexPath - ) as? ZoomingCollectionViewCell else { - return UICollectionViewCell() - } - - cell.setImage(images[indexPath.row]) - cell.onCloseButtonTap = { [weak self] in - self?.closeButtonPublisher.send() - } - return cell - } -} - -extension ZoomingCollectionView: UICollectionViewDelegateFlowLayout { - - func collectionView( - _ collectionView: UICollectionView, - layout collectionViewLayout: UICollectionViewLayout, - sizeForItemAt indexPath: IndexPath - ) -> CGSize { - collectionView.bounds.size - } -} - -extension ZoomingCollectionView { - - private func setUpCollectionView() { - register( - ZoomingCollectionViewCell.self, - forCellWithReuseIdentifier: ZoomingCollectionViewCell.identifier - ) - delegate = self - dataSource = self - isPagingEnabled = true - isScrollEnabled = false - showsHorizontalScrollIndicator = false - showsVerticalScrollIndicator = false - backgroundColor = .clear - } -} diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift deleted file mode 100644 index 14398994b..000000000 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift +++ /dev/null @@ -1,85 +0,0 @@ -// -// ZoomingCollectionViewCell.swift -// koin -// -// Created by 홍기정 on 4/22/26. -// - -import UIKit - -final class ZoomingCollectionViewCell: UICollectionViewCell { - - var onCloseButtonTap: (() -> Void)? - - private let imageView: UIImageView = { - let imageView = UIImageView() - imageView.contentMode = .scaleAspectFit - imageView.clipsToBounds = true - return imageView - }() - - private var imageAspectRatioConstraint: NSLayoutConstraint? - - private let closeButton: UIButton = { - let button = UIButton() - button.setImage(UIImage.appImage(asset: .cancel), for: .normal) - return button - }() - - override init(frame: CGRect) { - super.init(frame: frame) - configureView() - closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func prepareForReuse() { - super.prepareForReuse() - imageView.image = nil - onCloseButtonTap = nil - imageAspectRatioConstraint?.isActive = false - imageAspectRatioConstraint = nil - } - - func setImage(_ image: UIImage?) { - imageView.image = image - - imageAspectRatioConstraint?.isActive = false - if let image, image.size.width > 0 { - let ratio = image.size.height / image.size.width - let constraint = imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: ratio) - constraint.priority = .defaultHigh - constraint.isActive = true - imageAspectRatioConstraint = constraint - } - } - - @objc private func closeButtonTapped() { - onCloseButtonTap?() - } -} - -extension ZoomingCollectionViewCell { - - private func configureView() { - contentView.addSubview(imageView) - contentView.addSubview(closeButton) - - imageView.snp.makeConstraints { make in - make.leading.trailing.equalToSuperview() - make.centerY.equalToSuperview() - make.top.greaterThanOrEqualTo(contentView.safeAreaLayoutGuide.snp.top).offset(24) - make.bottom.lessThanOrEqualTo(contentView.safeAreaLayoutGuide.snp.bottom) - } - - closeButton.snp.makeConstraints { make in - make.width.height.equalTo(24) - make.bottom.equalTo(imageView.snp.top).offset(-8) - make.trailing.equalTo(imageView.snp.trailing) - } - } -} diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index 3efdecb46..d06fffe9d 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -5,182 +5,112 @@ // Created by 김나훈 on 4/8/24. // -import Combine +import SnapKit import UIKit final class ZoomedImageViewController: UIViewController { - + // MARK: - Properties - - private var cancellables: Set = [] - private var currentIndex = 0 - + + private var imageRatioConstraint: Constraint? + // MARK: - UI Components - + private let scrollView = UIScrollView().then { $0.minimumZoomScale = 1.0 $0.maximumZoomScale = 6.0 - $0.backgroundColor = .clear + $0.clipsToBounds = false $0.showsVerticalScrollIndicator = false $0.showsHorizontalScrollIndicator = false } - - private let collectionView = ZoomingCollectionView() - - private let nextButton: UIButton = { - let button = UIButton() - let image = UIImage(systemName: "arrow.right")? - .withTintColor(UIColor.appColor(.neutral0), renderingMode: .alwaysOriginal) - button.setImage(image, for: .normal) - button.layer.cornerRadius = 22 - button.backgroundColor = UIColor.appColor(.neutral800).withAlphaComponent(0.5) - return button - }() - - private let prevButton: UIButton = { - let button = UIButton() - let image = UIImage(systemName: "arrow.left")? - .withTintColor(UIColor.appColor(.neutral0), renderingMode: .alwaysOriginal) - button.setImage(image, for: .normal) - button.layer.cornerRadius = 22 - button.backgroundColor = UIColor.appColor(.neutral800).withAlphaComponent(0.5) - return button - }() - + + private let imageView = UIImageView().then { + $0.contentMode = .scaleAspectFit + } + + private let closeButton = UIButton().then { + $0.setImage(UIImage.appImage(asset: .cancel), for: .normal) + } + // MARK: - Initialize - + init() { super.init(nibName: nil, bundle: nil) modalPresentationStyle = .fullScreen modalTransitionStyle = .coverVertical } - + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + // MARK: - Life Cycle - + override func viewDidLoad() { super.viewDidLoad() configureView() - setupScrollView() - bind() + updateImageRatio() + scrollView.delegate = self + closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) } - + override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - - if scrollView.zoomScale == scrollView.minimumZoomScale { - centerScrollViewContents() - } + guard scrollView.zoomScale == scrollView.minimumZoomScale else { return } + imageView.frame = CGRect(origin: .zero, size: scrollView.bounds.size) + scrollView.contentSize = scrollView.bounds.size } - + func setImage(_ image: UIImage?) { - currentIndex = 0 - collectionView.setImage(image) - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) - updateButtonVisibility() - centerScrollViewContents() - } - - func setImages(_ images: [UIImage?]) { - currentIndex = 0 - collectionView.setImages(images) - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) - updateButtonVisibility() - centerScrollViewContents() + imageView.image = image + updateImageRatio() } } extension ZoomedImageViewController { - + private func configureView() { view.backgroundColor = .black view.addSubview(scrollView) - scrollView.addSubview(collectionView) - view.addSubview(nextButton) - view.addSubview(prevButton) - + scrollView.addSubview(imageView) + view.addSubview(closeButton) + scrollView.snp.makeConstraints { make in - make.edges.equalToSuperview() - } - - collectionView.snp.makeConstraints { make in - make.edges.equalTo(scrollView.contentLayoutGuide) - make.width.equalTo(scrollView.frameLayoutGuide) - make.height.equalTo(scrollView.frameLayoutGuide) + make.leading.trailing.equalToSuperview() + make.centerY.equalToSuperview() + make.top.greaterThanOrEqualTo(view.safeAreaLayoutGuide.snp.top).offset(24) + make.bottom.lessThanOrEqualTo(view.safeAreaLayoutGuide.snp.bottom) } - - nextButton.snp.makeConstraints { make in - make.centerY.equalTo(view.safeAreaLayoutGuide) - make.trailing.equalToSuperview() - make.width.height.equalTo(44) - } - - prevButton.snp.makeConstraints { make in - make.centerY.equalTo(view.safeAreaLayoutGuide) - make.leading.equalToSuperview() - make.width.height.equalTo(44) + + closeButton.snp.makeConstraints { make in + make.width.height.equalTo(24) + make.bottom.equalTo(scrollView.snp.top).offset(-8) + make.trailing.equalTo(scrollView) } } - - private func setupScrollView() { - scrollView.delegate = self - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - prevButton.addTarget(self, action: #selector(prevButtonTapped), for: .touchUpInside) - } - - private func bind() { - collectionView.closeButtonPublisher - .sink { [weak self] in - self?.dismiss(animated: true) - } - .store(in: &cancellables) - } - - private func centerScrollViewContents() { - let offsetX = max((scrollView.bounds.width - scrollView.contentSize.width) * 0.5, 0) - let offsetY = max((scrollView.bounds.height - scrollView.contentSize.height) * 0.5, 0) - scrollView.contentInset = UIEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: offsetX) - } - - private func updateButtonVisibility() { - nextButton.isHidden = currentIndex >= collectionView.imageCount - 1 - prevButton.isHidden = currentIndex <= 0 - } - - @objc private func nextButtonTapped() { - if currentIndex < collectionView.imageCount - 1 { - currentIndex += 1 - collectionView.showImage(at: currentIndex, animated: true) + + private func updateImageRatio() { + let size = imageView.image?.size ?? .zero + let ratio = size.width > 0 ? size.height / size.width : 1 + imageRatioConstraint?.deactivate() + scrollView.snp.makeConstraints { make in + imageRatioConstraint = make.height.equalTo(scrollView.snp.width).multipliedBy(ratio).priority(.high).constraint } - updateButtonVisibility() } - - @objc private func prevButtonTapped() { - if currentIndex > 0 { - currentIndex -= 1 - collectionView.showImage(at: currentIndex, animated: true) - } - updateButtonVisibility() + + @objc private func closeButtonTapped() { + dismiss(animated: true) } } extension ZoomedImageViewController: UIScrollViewDelegate { - + func viewForZooming(in scrollView: UIScrollView) -> UIView? { - collectionView - } - - func scrollViewDidZoom(_ scrollView: UIScrollView) { - centerScrollViewContents() + imageView } - + func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { - UIView.animate(withDuration: 0.3) { - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) - } + scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true) } } diff --git a/koin.xcodeproj/project.pbxproj b/koin.xcodeproj/project.pbxproj index bd58930c1..d46056453 100644 --- a/koin.xcodeproj/project.pbxproj +++ b/koin.xcodeproj/project.pbxproj @@ -1235,8 +1235,6 @@ E5DD3F6BE6C501B7B3BD659C /* RecruitPostRoleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F670021A95E0AA103E8F7BED /* RecruitPostRoleView.swift */; }; E7EB12C06B3F32702DE1BDDB /* RecruitNotificationListDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B18A7091B73080A7AEDDDE /* RecruitNotificationListDto.swift */; }; F0F216EDAA69B52CBEC0E606 /* RecruitPostViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288BC1E04044DC3FB48524FC /* RecruitPostViewModel.swift */; }; - F1A000010000000000000001 /* ZoomingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A000010000000000000002 /* ZoomingCollectionView.swift */; }; - F1A000010000000000000003 /* ZoomingCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */; }; F7F814BB370C922B6D8AA6EF /* RecruitStepView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFEC522ED41CF624AD3CB3A6 /* RecruitStepView.swift */; }; FBCFB1EF499995884A6F2E83 /* RecruitPostSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D65EF9E2B65CAE83F8017DD /* RecruitPostSchedule.swift */; }; FC40DDB1CAB3573658F94721 /* StudentAcademicInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5AA513615BE12CD677F848 /* StudentAcademicInfoDto.swift */; }; @@ -2502,8 +2500,6 @@ ED038AB5420C8C565688CF6B /* DefaultRecruitRepository.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DefaultRecruitRepository.swift; sourceTree = ""; }; EFEC522ED41CF624AD3CB3A6 /* RecruitStepView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = RecruitStepView.swift; sourceTree = ""; }; F04DE3DD779FBB7BEB86A567 /* PickerAppearanceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerAppearanceDelegate.swift; sourceTree = ""; }; - F1A000010000000000000002 /* ZoomingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomingCollectionView.swift; sourceTree = ""; }; - F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomingCollectionViewCell.swift; sourceTree = ""; }; F483F8DD8FCE3104599410C0 /* KoinPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinPickerView.swift; sourceTree = ""; }; F670021A95E0AA103E8F7BED /* RecruitPostRoleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitPostRoleView.swift; sourceTree = ""; }; FA5AA513615BE12CD677F848 /* StudentAcademicInfoDto.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = StudentAcademicInfoDto.swift; sourceTree = ""; }; @@ -3999,21 +3995,11 @@ 7CC42B062F56A7E900940CE1 /* ZoomedImageViewController */ = { isa = PBXGroup; children = ( - 7CC42B072F56A7F600940CE1 /* Subviews */, D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */, ); path = ZoomedImageViewController; sourceTree = ""; }; - 7CC42B072F56A7F600940CE1 /* Subviews */ = { - isa = PBXGroup; - children = ( - F1A000010000000000000002 /* ZoomingCollectionView.swift */, - F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */, - ); - path = Subviews; - sourceTree = ""; - }; 7CC42B082F56AAAD00940CE1 /* CallVan */ = { isa = PBXGroup; children = ( @@ -7798,8 +7784,6 @@ D2A8F8C02C4BCD470090C7A4 /* ShareMenuListUseCase.swift in Sources */, 7C61D3452F220E98005FAC3A /* EditLostItemImagesView.swift in Sources */, D2908D502BBE64B90008F908 /* Removetimetable.swift in Sources */, - F1A000010000000000000001 /* ZoomingCollectionView.swift in Sources */, - F1A000010000000000000003 /* ZoomingCollectionViewCell.swift in Sources */, D2F13E5D2BD0BA2B00172A9D /* NotiAgreementDto.swift in Sources */, 8354BE472C79FCA0009D4D7A /* Model.xcdatamodeld in Sources */, 7C372F292F1D6A7F00149729 /* LostItemDataViewModel.swift in Sources */, From ef0bad96a7335ce4a0b0624359fb5b0f6545cd7c Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 20:41:01 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat:=20=EC=8B=9D=EB=8B=A8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=ED=99=95=EB=8C=80=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=9D=84=20ZoomedImageViewController=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZoomedImageViewController.swift | 7 +++++++ .../Dining/Dining/DiningHostingController.swift | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index d06fffe9d..8490fbf50 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -5,6 +5,7 @@ // Created by 김나훈 on 4/8/24. // +import Kingfisher import SnapKit import UIKit @@ -66,6 +67,12 @@ final class ZoomedImageViewController: UIViewController { imageView.image = image updateImageRatio() } + + func setImage(url: String) { + imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] _ in + self?.updateImageRatio() + }) + } } extension ZoomedImageViewController { diff --git a/Koin/Presentation/Dining/Dining/DiningHostingController.swift b/Koin/Presentation/Dining/Dining/DiningHostingController.swift index 3d0056620..2874c7115 100644 --- a/Koin/Presentation/Dining/Dining/DiningHostingController.swift +++ b/Koin/Presentation/Dining/Dining/DiningHostingController.swift @@ -263,9 +263,8 @@ extension DiningHostingController { extension DiningHostingController { private func showZoomedImage(imageUrl: String) { - let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) - zoomedImageViewController.configure(url: imageUrl) - zoomedImageViewController.modalPresentationStyle = .overFullScreen + let zoomedImageViewController = ZoomedImageViewController() + zoomedImageViewController.setImage(url: imageUrl) present(zoomedImageViewController, animated: true) } } From 06dbefd558c303079e0ec14814bc58b49fdccb15 Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 20:41:01 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat:=20ZoomedImageViewController=20?= =?UTF-8?q?=EC=95=84=EB=9E=98=EB=A1=9C=20=EB=81=8C=EC=96=B4=20=EB=8B=AB?= =?UTF-8?q?=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZoomedImageViewController.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index 8490fbf50..9cf3cea95 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -14,6 +14,7 @@ final class ZoomedImageViewController: UIViewController { // MARK: - Properties private var imageRatioConstraint: Constraint? + private var initialTouchPoint = CGPoint.zero // MARK: - UI Components @@ -54,6 +55,7 @@ final class ZoomedImageViewController: UIViewController { updateImageRatio() scrollView.delegate = self closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) + view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureDismiss))) } override func viewDidLayoutSubviews() { @@ -109,6 +111,20 @@ extension ZoomedImageViewController { @objc private func closeButtonTapped() { dismiss(animated: true) } + + @objc private func panGestureDismiss(_ sender: UIPanGestureRecognizer) { + let touchPoint = sender.location(in: view.window) + switch sender.state { + case .began: + initialTouchPoint = touchPoint + case .changed, .ended, .cancelled: + guard scrollView.zoomScale == scrollView.minimumZoomScale, + 50 < touchPoint.y - initialTouchPoint.y else { return } + dismiss(animated: true) + default: + return + } + } } extension ZoomedImageViewController: UIScrollViewDelegate { From 1ce26fedccd452be1d864336a2546ef60255c8de Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 20:41:01 +0900 Subject: [PATCH 04/11] =?UTF-8?q?refactor:=20ZoomedImageViewControllerB=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EC=9C=84=EC=B9=98=EB=A5=BC=20selectedInde?= =?UTF-8?q?x=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subviews/ZoomedImageCollectionView.swift | 8 ++++---- .../Subviews/ZoomedImageRootViewController.swift | 6 +++--- .../ZoomedImageViewControllerB.swift | 5 +++-- .../LostItemChat/LostItemChatViewController.swift | 2 +- .../LostItemData/LostItemDataViewController.swift | 2 +- .../Shop/ShopBenefit/ShopBenefitViewController.swift | 2 +- .../Shop/ShopReviewList/ReviewListViewController.swift | 2 +- .../Shop/ShopSummary/ShopSummaryViewController.swift | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift index 1df2e69bb..5bfa0c303 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift @@ -12,7 +12,7 @@ final class ZoomedImageCollectionView: UICollectionView { // MARK: - Properties private var urls: [String] = [] - private var initialIndexPath: IndexPath = IndexPath(row: 0, section: 0) + private var initialIndex = 0 let updateTitlePublisher = PassthroughSubject() let hideNavigationBarPublisher = PassthroughSubject() private var isInitialized = false @@ -34,16 +34,16 @@ final class ZoomedImageCollectionView: UICollectionView { } // MARK: - Configure - func configure(urls: [String], initialIndexPath: IndexPath) { + func configure(urls: [String], initialIndex: Int) { self.urls = urls - self.initialIndexPath = initialIndexPath + self.initialIndex = initialIndex reloadData() } override func layoutSubviews() { super.layoutSubviews() if !isInitialized { - contentOffset = CGPoint(x: UIScreen.main.bounds.width * CGFloat(initialIndexPath.row), y: 0) + contentOffset = CGPoint(x: UIScreen.main.bounds.width * CGFloat(initialIndex), y: 0) isInitialized = true } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift index 5b2d44863..0786b1b47 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift @@ -57,10 +57,10 @@ final class ZoomedImageRootViewController: UIViewController { } // MARK: - Configure - func configure(urls: [String], initialIndexPath: IndexPath) { - zoomedImageCollectionView.configure(urls: urls, initialIndexPath: initialIndexPath) + func configure(urls: [String], initialIndex: Int) { + zoomedImageCollectionView.configure(urls: urls, initialIndex: initialIndex) if shouldShowTitle { - title = "\(initialIndexPath.row+1)/\(urls.count)" + title = "\(initialIndex + 1)/\(urls.count)" } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift index 6089aa565..600bee6e5 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift @@ -33,7 +33,8 @@ final class ZoomedImageViewControllerB: UINavigationController { configure(urls: [url]) } - func configure(urls: [String], initialIndexPath: IndexPath = IndexPath(row: 0, section: 0)) { - rootViewController.configure(urls: urls, initialIndexPath: initialIndexPath) + func configure(urls: [String], selectedIndex: Int = 0) { + let index = urls.indices.contains(selectedIndex) ? selectedIndex : 0 + rootViewController.configure(urls: urls, initialIndex: index) } } diff --git a/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift b/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift index b5b9bebb1..53cc82c33 100644 --- a/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift +++ b/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift @@ -84,7 +84,7 @@ final class LostItemChatViewController: UIViewController, PHPickerViewController self?.dismissKeyboard() let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) - zoomedImageViewController.configure(urls: [imageUrl], initialIndexPath: IndexPath(row: 0, section: 0)) + zoomedImageViewController.configure(url: imageUrl) self?.present(zoomedImageViewController, animated: true, completion: nil) }.store(in: &subscriptions) } diff --git a/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift b/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift index 4942d449e..17fcf007e 100644 --- a/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift +++ b/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift @@ -128,7 +128,7 @@ final class LostItemDataViewController: UIViewController { let viewController = ZoomedImageViewControllerB() viewController.configure( urls: imageUrls, - initialIndexPath: indexPath) + selectedIndex: indexPath.row) navigationController?.present(viewController, animated: true) }.store(in: &subscription) diff --git a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift index 20b83c8f6..efcc35140 100644 --- a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift +++ b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift @@ -54,7 +54,7 @@ final class ShopBenefitViewController: UIViewController { benefitsTableView.imageTapPublisher.sink { [weak self] (imageUrls, indexPath) in guard let self else { return } let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: indexPath) + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: indexPath.row) zoomedImageViewController.modalPresentationStyle = .fullScreen present(zoomedImageViewController, animated: true) }.store(in: &subscriptions) diff --git a/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift b/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift index f3a6fa225..2e30fe8f9 100644 --- a/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift +++ b/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift @@ -375,7 +375,7 @@ extension ReviewListViewController { private func showZoomedImage(_ imageUrls: [String], _ initialIndexpath: IndexPath) { let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: initialIndexpath) + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: initialIndexpath.row) present(zoomedImageViewController, animated: true) } } diff --git a/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift b/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift index f81351cad..4473ad6c1 100644 --- a/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift +++ b/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift @@ -294,7 +294,7 @@ extension ShopSummaryViewController { self.inputSubject.send(.logEvent(EventParameter.EventLabel.Shop.shopDetailPhotoViewOpenClick, self.viewModel.shopName)) let zoomedViewController = ZoomedImageViewControllerB() zoomedViewController.configure(urls: viewModel.cachedImages.map { return $0.imageUrl }, - initialIndexPath: indexPath) + selectedIndex: indexPath.row) self.present(zoomedViewController, animated: true) }.store(in: &subscriptions) } From 680ce604fae280748baf10b26072030492a22dc2 Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 22:21:03 +0900 Subject: [PATCH 05/11] =?UTF-8?q?feat:=20=ED=99=95=EB=8C=80=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A5=BC=20=EC=9C=A0=EC=A7=80=ED=95=98=EB=8A=94=20Zoo?= =?UTF-8?q?mableImageView=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Koin/Core/View/UIKit/ZoomableImageView.swift | 143 +++++++++++++++++++ koin.xcodeproj/project.pbxproj | 4 + 2 files changed, 147 insertions(+) create mode 100644 Koin/Core/View/UIKit/ZoomableImageView.swift diff --git a/Koin/Core/View/UIKit/ZoomableImageView.swift b/Koin/Core/View/UIKit/ZoomableImageView.swift new file mode 100644 index 000000000..007e0f9f4 --- /dev/null +++ b/Koin/Core/View/UIKit/ZoomableImageView.swift @@ -0,0 +1,143 @@ +// +// ZoomableImageView.swift +// koin +// +// Created by 홍기정 on 11/24/26. +// + +import Combine +import Kingfisher +import UIKit + +final class ZoomableImageView: UIScrollView { + + // MARK: - Properties + + @Published private(set) var isZoomed = false + @Published private(set) var fittedImageFrame: CGRect = .zero + private var lastBoundsSize: CGSize = .zero + private let maximumZoomFactor: CGFloat = 3 + + // MARK: - UI Components + + private let imageView = UIImageView() + + // MARK: - Initializer + + init() { + super.init(frame: .zero) + delegate = self + contentInsetAdjustmentBehavior = .never + showsVerticalScrollIndicator = false + showsHorizontalScrollIndicator = false + decelerationRate = .fast + addSubview(imageView) + + let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapped)) + doubleTapGesture.numberOfTapsRequired = 2 + addGestureRecognizer(doubleTapGesture) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Layout + + override func layoutSubviews() { + super.layoutSubviews() + guard bounds.size != lastBoundsSize else { return } + lastBoundsSize = bounds.size + updateZoomScales() + } + + // MARK: - Configure + + func setImage(_ image: UIImage?) { + imageView.image = image + resetImageLayout() + } + + func setImage(url: String) { + imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] _ in + self?.resetImageLayout() + }) + } + + func resetZoom() { + setZoomScale(minimumZoomScale, animated: false) + } +} + +extension ZoomableImageView { + + private func resetImageLayout() { + minimumZoomScale = 1 + maximumZoomScale = 1 + zoomScale = 1 + let imageSize = imageView.image?.size ?? .zero + imageView.frame = CGRect(origin: .zero, size: imageSize) + contentSize = imageSize + updateZoomScales() + } + + private func updateZoomScales() { + guard let imageSize = imageView.image?.size, + imageSize.width > 0, imageSize.height > 0, + bounds.width > 0, bounds.height > 0 else { + fittedImageFrame = CGRect(origin: .zero, size: bounds.size) + return + } + let fitScale = min(bounds.width / imageSize.width, bounds.height / imageSize.height) + minimumZoomScale = fitScale + maximumZoomScale = fitScale * maximumZoomFactor + zoomScale = fitScale + centerImage() + contentOffset = CGPoint(x: -contentInset.left, y: -contentInset.top) + isZoomed = false + + let fittedSize = CGSize(width: imageSize.width * fitScale, height: imageSize.height * fitScale) + fittedImageFrame = CGRect( + x: (bounds.width - fittedSize.width) / 2, + y: (bounds.height - fittedSize.height) / 2, + width: fittedSize.width, + height: fittedSize.height + ) + } + + private func centerImage() { + let horizontalInset = max((bounds.width - contentSize.width) / 2, 0) + let verticalInset = max((bounds.height - contentSize.height) / 2, 0) + contentInset = UIEdgeInsets(top: verticalInset, left: horizontalInset, bottom: verticalInset, right: horizontalInset) + } + + @objc private func doubleTapped(_ gesture: UITapGestureRecognizer) { + guard imageView.image != nil else { return } + if isZoomed { + setZoomScale(minimumZoomScale, animated: true) + return + } + let point = gesture.location(in: imageView) + let zoomSize = CGSize(width: bounds.width / maximumZoomScale, height: bounds.height / maximumZoomScale) + let zoomRect = CGRect( + x: point.x - zoomSize.width / 2, + y: point.y - zoomSize.height / 2, + width: zoomSize.width, + height: zoomSize.height + ) + zoom(to: zoomRect, animated: true) + } +} + +extension ZoomableImageView: UIScrollViewDelegate { + + func viewForZooming(in scrollView: UIScrollView) -> UIView? { + imageView + } + + func scrollViewDidZoom(_ scrollView: UIScrollView) { + centerImage() + isZoomed = zoomScale != minimumZoomScale + } +} diff --git a/koin.xcodeproj/project.pbxproj b/koin.xcodeproj/project.pbxproj index d46056453..5cf3c7f02 100644 --- a/koin.xcodeproj/project.pbxproj +++ b/koin.xcodeproj/project.pbxproj @@ -1070,6 +1070,7 @@ D22C54812C6A5957000826DA /* FileUploadResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C54802C6A5957000826DA /* FileUploadResponse.swift */; }; D22C54832C6A59C4000826DA /* UploadFileUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C54822C6A59C4000826DA /* UploadFileUseCase.swift */; }; D235829F2BC2F5D600D615DD /* ZoomedImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */; }; + D8C9A09DFDA097189C1CC6DC /* ZoomableImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */; }; D23944822C3C24A200048F45 /* ReviewsDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944812C3C24A200048F45 /* ReviewsDto.swift */; }; D23944842C3C3ABC00048F45 /* ShopReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944832C3C3ABC00048F45 /* ShopReview.swift */; }; D23944862C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944852C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift */; }; @@ -2327,6 +2328,7 @@ D22C54802C6A5957000826DA /* FileUploadResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadResponse.swift; sourceTree = ""; }; D22C54822C6A59C4000826DA /* UploadFileUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadFileUseCase.swift; sourceTree = ""; }; D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomedImageViewController.swift; sourceTree = ""; }; + 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableImageView.swift; sourceTree = ""; }; D23944812C3C24A200048F45 /* ReviewsDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewsDto.swift; sourceTree = ""; }; D23944832C3C3ABC00048F45 /* ShopReview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopReview.swift; sourceTree = ""; }; D23944852C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchShopReviewListUseCase.swift; sourceTree = ""; }; @@ -3209,6 +3211,7 @@ 7CED8ED32EF2D1F900457128 /* CancelableImageView.swift */, 7CC42B062F56A7E900940CE1 /* ZoomedImageViewController */, 7CA0D6172EC744E700E9A282 /* ZoomedImageViewControllerB */, + 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */, 7C333E7A302E280C009D2B89 /* KoinModalViewController */, D2FB23442BFB6D090098BA2B /* CustomNavigationController.swift */, D27A5D992C6B97D200C4275F /* InsetLabel.swift */, @@ -7888,6 +7891,7 @@ 7C16AA392F3E9FBC0071ABE6 /* ErrorViewController.swift in Sources */, 7CF77B6B30056ED4003642C1 /* NoticeKeywordAddButton.swift in Sources */, D235829F2BC2F5D600D615DD /* ZoomedImageViewController.swift in Sources */, + D8C9A09DFDA097189C1CC6DC /* ZoomableImageView.swift in Sources */, D249CD262C12DC2C000813F9 /* FetchDiningListUseCase.swift in Sources */, B46B8CC42E76CC6300A8E797 /* FetchShopSummaryUseCase.swift in Sources */, D20AD70B2E036BC60067760A /* ResetPasswordEmailUseCase.swift in Sources */, From 9f8b17e8dc1f3241be800998907e1fc101ae5a7b Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 22:21:03 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor:=20ZoomedImageViewController?= =?UTF-8?q?=EC=97=90=20ZoomableImageView=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZoomedImageViewController.swift | 100 ++++++++---------- 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index 9cf3cea95..c335a602b 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -5,7 +5,7 @@ // Created by 김나훈 on 4/8/24. // -import Kingfisher +import Combine import SnapKit import UIKit @@ -13,21 +13,15 @@ final class ZoomedImageViewController: UIViewController { // MARK: - Properties - private var imageRatioConstraint: Constraint? + private var subscriptions: Set = [] private var initialTouchPoint = CGPoint.zero + private let closeButtonSize: CGFloat = 24 + private let closeButtonSpacing: CGFloat = 8 // MARK: - UI Components - private let scrollView = UIScrollView().then { - $0.minimumZoomScale = 1.0 - $0.maximumZoomScale = 6.0 + private let zoomableImageView = ZoomableImageView().then { $0.clipsToBounds = false - $0.showsVerticalScrollIndicator = false - $0.showsHorizontalScrollIndicator = false - } - - private let imageView = UIImageView().then { - $0.contentMode = .scaleAspectFit } private let closeButton = UIButton().then { @@ -47,64 +41,73 @@ final class ZoomedImageViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + override var preferredStatusBarStyle: UIStatusBarStyle { + .lightContent + } + // MARK: - Life Cycle override func viewDidLoad() { super.viewDidLoad() + additionalSafeAreaInsets.top = closeButtonSize + closeButtonSpacing configureView() - updateImageRatio() - scrollView.delegate = self + bind() closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureDismiss))) } - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - guard scrollView.zoomScale == scrollView.minimumZoomScale else { return } - imageView.frame = CGRect(origin: .zero, size: scrollView.bounds.size) - scrollView.contentSize = scrollView.bounds.size - } - func setImage(_ image: UIImage?) { - imageView.image = image - updateImageRatio() + zoomableImageView.setImage(image) } func setImage(url: String) { - imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] _ in - self?.updateImageRatio() - }) + zoomableImageView.setImage(url: url) } } extension ZoomedImageViewController { private func configureView() { - view.backgroundColor = .black - view.addSubview(scrollView) - scrollView.addSubview(imageView) + view.backgroundColor = .appColor(.neutral800) + view.addSubview(zoomableImageView) view.addSubview(closeButton) - scrollView.snp.makeConstraints { make in - make.leading.trailing.equalToSuperview() - make.centerY.equalToSuperview() - make.top.greaterThanOrEqualTo(view.safeAreaLayoutGuide.snp.top).offset(24) - make.bottom.lessThanOrEqualTo(view.safeAreaLayoutGuide.snp.bottom) + zoomableImageView.snp.makeConstraints { make in + make.edges.equalTo(view.safeAreaLayoutGuide) } closeButton.snp.makeConstraints { make in - make.width.height.equalTo(24) - make.bottom.equalTo(scrollView.snp.top).offset(-8) - make.trailing.equalTo(scrollView) + make.width.height.equalTo(closeButtonSize) + make.trailing.equalTo(zoomableImageView.snp.leading) + make.bottom.equalTo(zoomableImageView.snp.top).offset(-closeButtonSpacing) } } - private func updateImageRatio() { - let size = imageView.image?.size ?? .zero - let ratio = size.width > 0 ? size.height / size.width : 1 - imageRatioConstraint?.deactivate() - scrollView.snp.makeConstraints { make in - imageRatioConstraint = make.height.equalTo(scrollView.snp.width).multipliedBy(ratio).priority(.high).constraint + private func bind() { + zoomableImageView.$fittedImageFrame + .sink { [weak self] fittedImageFrame in + self?.updateCloseButtonPosition(fittedImageFrame) + } + .store(in: &subscriptions) + + zoomableImageView.$isZoomed + .removeDuplicates() + .sink { [weak self] isZoomed in + UIView.animate( + withDuration: isZoomed ? 0.1 : 0.2, + delay: 0, + options: [.overrideInheritedDuration, .overrideInheritedCurve] + ) { + self?.closeButton.alpha = isZoomed ? 0 : 1 + } + } + .store(in: &subscriptions) + } + + private func updateCloseButtonPosition(_ fittedImageFrame: CGRect) { + closeButton.snp.updateConstraints { make in + make.trailing.equalTo(zoomableImageView.snp.leading).offset(fittedImageFrame.maxX) + make.bottom.equalTo(zoomableImageView.snp.top).offset(fittedImageFrame.minY - closeButtonSpacing) } } @@ -118,7 +121,7 @@ extension ZoomedImageViewController { case .began: initialTouchPoint = touchPoint case .changed, .ended, .cancelled: - guard scrollView.zoomScale == scrollView.minimumZoomScale, + guard !zoomableImageView.isZoomed, 50 < touchPoint.y - initialTouchPoint.y else { return } dismiss(animated: true) default: @@ -126,14 +129,3 @@ extension ZoomedImageViewController { } } } - -extension ZoomedImageViewController: UIScrollViewDelegate { - - func viewForZooming(in scrollView: UIScrollView) -> UIView? { - imageView - } - - func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true) - } -} From fbb862b9451ca3d11e81a1bd30766908c7a5289e Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 22:21:03 +0900 Subject: [PATCH 07/11] =?UTF-8?q?refactor:=20ZoomedImageViewControllerB?= =?UTF-8?q?=EC=97=90=20ZoomableImageView=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subviews/ZoomedImageCollectionView.swift | 19 ++++-- .../ZoomedImageCollectionViewCell.swift | 65 +++++-------------- .../ZoomedImageRootViewController.swift | 3 +- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift index 5bfa0c303..084cd48bc 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift @@ -21,7 +21,6 @@ final class ZoomedImageCollectionView: UICollectionView { override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { let layout = UICollectionViewFlowLayout().then { $0.scrollDirection = .horizontal - $0.itemSize = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) $0.minimumLineSpacing = 0 $0.minimumInteritemSpacing = 0 } @@ -33,6 +32,10 @@ final class ZoomedImageCollectionView: UICollectionView { fatalError("init(coder:) has not been implemented") } + var isCurrentImageZoomed: Bool { + visibleCells.contains { ($0 as? ZoomedImageCollectionViewCell)?.isZoomed == true } + } + // MARK: - Configure func configure(urls: [String], initialIndex: Int) { self.urls = urls @@ -42,8 +45,8 @@ final class ZoomedImageCollectionView: UICollectionView { override func layoutSubviews() { super.layoutSubviews() - if !isInitialized { - contentOffset = CGPoint(x: UIScreen.main.bounds.width * CGFloat(initialIndex), y: 0) + if !isInitialized, 0 < bounds.width { + contentOffset = CGPoint(x: bounds.width * CGFloat(initialIndex), y: 0) isInitialized = true } } @@ -65,6 +68,14 @@ extension ZoomedImageCollectionView: UICollectionViewDataSource { } extension ZoomedImageCollectionView: UICollectionViewDelegateFlowLayout { + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return collectionView.bounds.size + } + + func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + (cell as? ZoomedImageCollectionViewCell)?.resetZoom() + } func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { let width = self.frame.width @@ -89,6 +100,6 @@ extension ZoomedImageCollectionView { isPagingEnabled = true showsHorizontalScrollIndicator = false contentInsetAdjustmentBehavior = .never - backgroundColor = .black + backgroundColor = .appColor(.neutral800) } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift index a6043ad6d..62d335ffb 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift @@ -6,78 +6,47 @@ // import UIKit -import Combine final class ZoomedImageCollectionViewCell: UICollectionViewCell { - + // MARK: - UI Components - let scrollView = UIScrollView().then { - $0.minimumZoomScale = 1.0 - $0.maximumZoomScale = 3.0 - $0.showsVerticalScrollIndicator = false - $0.showsHorizontalScrollIndicator = false - } - let imageView = UIImageView().then { - $0.contentMode = .scaleAspectFit + private let zoomableImageView = ZoomableImageView() + + var isZoomed: Bool { + zoomableImageView.isZoomed } - + // MARK: - Initializer override init(frame: CGRect) { super.init(frame: .zero) configureView() - setDelegate() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + // MARK: - Configure func configure(url: String) { - imageView.kf.setImage( - with: URL(string: url) - ) + zoomableImageView.setImage(url: url) + } + + func resetZoom() { + zoomableImageView.resetZoom() } - + // MARK: - PrepareForReuse override func prepareForReuse() { super.prepareForReuse() - - scrollView.zoomScale = 1.0 - imageView.image = nil - } -} - -extension ZoomedImageCollectionViewCell: UIScrollViewDelegate { - - func viewForZooming(in scrollView: UIScrollView) -> UIView? { - return imageView - } - - func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { - UIView.animate(withDuration: 0.3) { [weak self] in - self?.scrollView.zoomScale = 1.0 - } + zoomableImageView.setImage(nil) } } extension ZoomedImageCollectionViewCell { - - private func setDelegate() { - scrollView.delegate = self - } - + private func configureView() { - contentView.addSubview(scrollView) - scrollView.addSubview(imageView) - - scrollView.snp.makeConstraints { + contentView.addSubview(zoomableImageView) + zoomableImageView.snp.makeConstraints { $0.edges.equalToSuperview() - $0.width.equalToSuperview() - } - imageView.snp.makeConstraints { - $0.height.equalToSuperview() - $0.width.equalToSuperview() - $0.centerY.equalToSuperview() } } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift index 0786b1b47..4967f682a 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift @@ -96,7 +96,8 @@ extension ZoomedImageRootViewController { case .began: initialTouchPoint = touchPoint case .changed, .ended, .cancelled: - if 50 < touchPoint.y - initialTouchPoint.y { + if !zoomedImageCollectionView.isCurrentImageZoomed, + 50 < touchPoint.y - initialTouchPoint.y { dismiss(animated: true) } default: From 1a5a7973ae6f93d4630f56c78a8a5e0d0e558b58 Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 22:21:03 +0900 Subject: [PATCH 08/11] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=ED=99=95=EB=8C=80=20=ED=99=94=EB=A9=B4=20present=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=EC=9D=84=20fullScreen=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift | 2 +- .../CallVan/CallVanChat/CallVanChatViewController.swift | 1 - .../Recruit/RecruitChat/RecruitChatViewController.swift | 1 - .../Shop/ShopBenefit/ShopBenefitViewController.swift | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift index 600bee6e5..a2c0d9e85 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift @@ -17,7 +17,7 @@ final class ZoomedImageViewControllerB: UINavigationController { rootViewController = ZoomedImageRootViewController(shouldShowTitle: shouldShowTitle) super.init(rootViewController: rootViewController) - modalPresentationStyle = .overCurrentContext + modalPresentationStyle = .fullScreen modalTransitionStyle = .coverVertical } required init?(coder aDecoder: NSCoder) { diff --git a/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift b/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift index 698c1ae42..8cf222e20 100644 --- a/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift +++ b/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift @@ -93,7 +93,6 @@ final class CallVanChatViewController: UIViewController { .sink { [weak self] imageUrl in let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) zoomedImageViewController.configure(url: imageUrl) - zoomedImageViewController.modalPresentationStyle = .overFullScreen self?.present(zoomedImageViewController, animated: true) } .store(in: &subscriptions) diff --git a/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift b/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift index c31bbd34a..1a52dc6ce 100644 --- a/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift +++ b/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift @@ -174,7 +174,6 @@ extension RecruitChatViewController { private func presentZoomedImageViewControllerB(_ imageUrl: String) { let viewController = ZoomedImageViewControllerB(shouldShowTitle: false) viewController.configure(url: imageUrl) - viewController.modalPresentationStyle = .overFullScreen present(viewController, animated: true) } } diff --git a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift index efcc35140..756d9acf8 100644 --- a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift +++ b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift @@ -55,7 +55,6 @@ final class ShopBenefitViewController: UIViewController { guard let self else { return } let zoomedImageViewController = ZoomedImageViewControllerB() zoomedImageViewController.configure(urls: imageUrls, selectedIndex: indexPath.row) - zoomedImageViewController.modalPresentationStyle = .fullScreen present(zoomedImageViewController, animated: true) }.store(in: &subscriptions) From 5a335a7d4a0b3a0886cd360a02f0d7417020121e Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 23:23:04 +0900 Subject: [PATCH 09/11] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=ED=99=95=EB=8C=80=20=ED=99=94=EB=A9=B4=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZoomedImageViewController.swift | 1 - .../Subviews/ZoomedImageCollectionView.swift | 1 - .../Subviews/ZoomedImageRootViewController.swift | 9 +-------- .../ZoomedImageViewControllerB.swift | 3 +-- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index c335a602b..e4a00a05e 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -33,7 +33,6 @@ final class ZoomedImageViewController: UIViewController { init() { super.init(nibName: nil, bundle: nil) modalPresentationStyle = .fullScreen - modalTransitionStyle = .coverVertical } @available(*, unavailable) diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift index 084cd48bc..2157b7995 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift @@ -14,7 +14,6 @@ final class ZoomedImageCollectionView: UICollectionView { private var urls: [String] = [] private var initialIndex = 0 let updateTitlePublisher = PassthroughSubject() - let hideNavigationBarPublisher = PassthroughSubject() private var isInitialized = false // MARK: - Initializer diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift index 4967f682a..7fe81ce91 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift @@ -72,10 +72,6 @@ final class ZoomedImageRootViewController: UIViewController { self.title = title } }.store(in: &subscriptions) - - zoomedImageCollectionView.hideNavigationBarPublisher.sink { [weak self] isHidden in - self?.navigationController?.setNavigationBarHidden(isHidden, animated: true) - }.store(in: &subscriptions) } } @@ -88,10 +84,7 @@ extension ZoomedImageRootViewController { @objc private func panGestureDismiss(_ sender: UIGestureRecognizer) { let touchPoint = sender.location(in: view.window) - - if sender.state == .began { - initialTouchPoint = touchPoint - } + switch sender.state { case .began: initialTouchPoint = touchPoint diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift index a2c0d9e85..640f98224 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift @@ -10,7 +10,7 @@ import UIKit final class ZoomedImageViewControllerB: UINavigationController { // MARK: - Properties - let rootViewController: ZoomedImageRootViewController + private let rootViewController: ZoomedImageRootViewController // MARK: - Initializer init(shouldShowTitle: Bool = true) { @@ -18,7 +18,6 @@ final class ZoomedImageViewControllerB: UINavigationController { super.init(rootViewController: rootViewController) modalPresentationStyle = .fullScreen - modalTransitionStyle = .coverVertical } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") From b202748f6e5948a355cdf74a7dda97f31b49d15d Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Tue, 24 Nov 2026 23:50:43 +0900 Subject: [PATCH 10/11] =?UTF-8?q?fix:=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Koin/Core/View/UIKit/ZoomableImageView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Koin/Core/View/UIKit/ZoomableImageView.swift b/Koin/Core/View/UIKit/ZoomableImageView.swift index 007e0f9f4..fe70b2702 100644 --- a/Koin/Core/View/UIKit/ZoomableImageView.swift +++ b/Koin/Core/View/UIKit/ZoomableImageView.swift @@ -60,7 +60,8 @@ final class ZoomableImageView: UIScrollView { } func setImage(url: String) { - imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] _ in + imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] result in + if case .failure(let error) = result, error.isNotCurrentTask { return } self?.resetImageLayout() }) } From 9e14a3d0d42aaa1b3219e1d8d48e09e7dd758cde Mon Sep 17 00:00:00 2001 From: GI JEONG HONG Date: Wed, 25 Nov 2026 00:09:10 +0900 Subject: [PATCH 11/11] =?UTF-8?q?fix:=20=EB=B3=B5=EB=8D=95=EB=B0=A9=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EB=8C=80=20configure=20=EC=9D=B8=EC=9E=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/Land/LandDetail/LandDetailViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift b/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift index 96e27a5ea..8de670bfa 100644 --- a/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift +++ b/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift @@ -118,7 +118,7 @@ extension LandDetailViewController { private func presentZoomedImage(imageUrls: [String], indexPath: IndexPath) { let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: indexPath) + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: indexPath.row) present(zoomedImageViewController, animated: true) }