-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 지도 탭 캐러셀 구현 + Extension 분리 #39
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
accd516
:sparkles: Feat: 지도 탭 캐러셀 구현
anyukyung 45490b3
:lipstick: Add: CarouselLayout 익스텐션으로 분리
anyukyung 3167bbe
:lipstick: Update: card 레이아웃 수정
anyukyung fe21645
Merge branch 'iOS/dev' into iOS/feat#26
anyukyung 0be1654
:rotating_light: Fix: identifier 변수 오버라이드 삭제
anyukyung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
iOS/Layover/Layover/Extensions/UICollectionViewLayout+.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// UICollectionViewLayout+.swift | ||
// Layover | ||
// | ||
// Created by kong on 2023/11/19. | ||
// Copyright © 2023 CodeBomber. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UICollectionViewLayout { | ||
static func createCarouselLayout(groupWidthDimension: CGFloat, | ||
groupHeightDimension: CGFloat, | ||
maximumZoomScale: CGFloat, | ||
minimumZoomScale: CGFloat) -> UICollectionViewLayout { | ||
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), | ||
heightDimension: .fractionalHeight(1)) | ||
let item = NSCollectionLayoutItem(layoutSize: itemSize) | ||
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(groupWidthDimension), | ||
heightDimension: .fractionalHeight(groupHeightDimension)) | ||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) | ||
let section = NSCollectionLayoutSection(group: group) | ||
section.orthogonalScrollingBehavior = .groupPagingCentered | ||
section.visibleItemsInvalidationHandler = { items, offset, environment in | ||
let containerWidth = environment.container.contentSize.width | ||
items.forEach { item in | ||
let distanceFromCenter = abs((item.center.x - offset.x) - environment.container.contentSize.width / 2.0) | ||
let scale = max(maximumZoomScale - (distanceFromCenter / containerWidth), minimumZoomScale) | ||
item.transform = CGAffineTransform(scaleX: scale, y: scale) | ||
} | ||
} | ||
return UICollectionViewCompositionalLayout(section: section) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
iOS/Layover/Layover/Scenes/MapScene/MapCarouselCollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// MapCarouselCollectionViewCell.swift | ||
// Layover | ||
// | ||
// Created by kong on 2023/11/17. | ||
// Copyright © 2023 CodeBomber. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
final class MapCarouselCollectionViewCell: UICollectionViewCell { | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
backgroundColor = .white | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 backgroundColor = .white들어가야 하는거 아닌가요? 그냥 앱이 종료되는 것만 막는 장치일까요? |
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,23 +15,15 @@ protocol MapDisplayLogic: AnyObject { | |
|
||
final class MapViewController: BaseViewController { | ||
|
||
// MARK: - UI Components | ||
|
||
private let mapView: MKMapView = { | ||
let mapView = MKMapView() | ||
mapView.showsUserLocation = true | ||
mapView.setUserTrackingMode(.follow, animated: true) | ||
return mapView | ||
}() | ||
|
||
private let currentLocationButton: LOCircleButton = { | ||
let button = LOCircleButton(style: .locate, diameter: 52) | ||
return button | ||
}() | ||
|
||
private let uploadButton: LOCircleButton = { | ||
let button = LOCircleButton(style: .add, diameter: 52) | ||
return button | ||
}() | ||
|
||
private let searchButton: UIButton = { | ||
var configuration = UIButton.Configuration.filled() | ||
var titleContainer = AttributeContainer() | ||
|
@@ -47,7 +39,29 @@ final class MapViewController: BaseViewController { | |
return button | ||
}() | ||
|
||
// MARK: - UI Components | ||
private let currentLocationButton: LOCircleButton = LOCircleButton(style: .locate, diameter: 52) | ||
|
||
private let uploadButton: LOCircleButton = LOCircleButton(style: .add, diameter: 52) | ||
|
||
private lazy var carouselCollectionView: UICollectionView = { | ||
let layout: UICollectionViewLayout = .createCarouselLayout(groupWidthDimension: 94/375, | ||
groupHeightDimension: 1.0, | ||
maximumZoomScale: 1.0, | ||
minimumZoomScale: 73/94) | ||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) | ||
collectionView.backgroundColor = .clear | ||
collectionView.register(MapCarouselCollectionViewCell.self, forCellWithReuseIdentifier: MapCarouselCollectionViewCell.identifier) | ||
return collectionView | ||
}() | ||
|
||
private lazy var carouselDatasource = UICollectionViewDiffableDataSource<UUID, Int>(collectionView: carouselCollectionView) { collectionView, indexPath, _ in | ||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MapCarouselCollectionViewCell.identifier, | ||
for: indexPath) as? MapCarouselCollectionViewCell else { return UICollectionViewCell() } | ||
cell.layer.cornerRadius = 10 | ||
return cell | ||
} | ||
|
||
// MARK: - Properties | ||
|
||
var interactor: MapBusinessLogic? | ||
|
||
|
@@ -57,17 +71,16 @@ final class MapViewController: BaseViewController { | |
super.viewDidLoad() | ||
MapConfigurator.shared.configure(self) | ||
interactor?.checkLocationAuthorizationStatus() | ||
setCarouselCollectionView() | ||
} | ||
|
||
// MARK: - UI + Layout | ||
|
||
override func setConstraints() { | ||
view.addSubviews(mapView, searchButton, currentLocationButton, uploadButton) | ||
|
||
mapView.translatesAutoresizingMaskIntoConstraints = false | ||
searchButton.translatesAutoresizingMaskIntoConstraints = false | ||
currentLocationButton.translatesAutoresizingMaskIntoConstraints = false | ||
uploadButton.translatesAutoresizingMaskIntoConstraints = false | ||
[mapView, searchButton, currentLocationButton, uploadButton, carouselCollectionView].forEach { | ||
view.addSubview($0) | ||
$0.translatesAutoresizingMaskIntoConstraints = false | ||
} | ||
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 결국 addSubviews는 안 쓰기로 합의가 된 것일까요 ?ㅅ? |
||
|
||
NSLayoutConstraint.activate([ | ||
mapView.topAnchor.constraint(equalTo: view.topAnchor), | ||
|
@@ -79,16 +92,33 @@ final class MapViewController: BaseViewController { | |
searchButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
searchButton.heightAnchor.constraint(equalToConstant: 42), | ||
|
||
uploadButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -15), | ||
uploadButton.bottomAnchor.constraint(equalTo: carouselCollectionView.topAnchor, constant: -15), | ||
uploadButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16), | ||
|
||
currentLocationButton.bottomAnchor.constraint(equalTo: uploadButton.topAnchor, constant: -10), | ||
currentLocationButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16) | ||
currentLocationButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16), | ||
|
||
carouselCollectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -19), | ||
carouselCollectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), | ||
carouselCollectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor), | ||
carouselCollectionView.heightAnchor.constraint(equalToConstant: 151) | ||
]) | ||
} | ||
|
||
private func setCarouselCollectionView() { | ||
carouselCollectionView.dataSource = carouselDatasource | ||
var snapshot = NSDiffableDataSourceSnapshot<UUID, Int>() | ||
snapshot.appendSections([UUID()]) | ||
snapshot.appendItems([1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
carouselDatasource.apply(snapshot) | ||
} | ||
|
||
} | ||
|
||
extension MapViewController: MapDisplayLogic { | ||
|
||
} | ||
|
||
#Preview { | ||
MapViewController() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨네요. 추후 홈 뷰에 쓰인 코드도 이걸 사용하도록 바꿔야겠어요