Skip to content

Commit

Permalink
Feat/#11 모달UI
Browse files Browse the repository at this point in the history
모달뷰 UI 세부사항(머문시간, 주소, 좌표)
  • Loading branch information
EvelynMacbookPro committed Aug 18, 2024
1 parent 8d19228 commit 40758e6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 21 deletions.
4 changes: 4 additions & 0 deletions MC2Maps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
A88329EE2C6DEBCC00D6CC87 /* MapLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */; };
A88329F22C71EA6100D6CC87 /* ModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88329F12C71EA6100D6CC87 /* ModalView.swift */; };
EAF2746D2C1C6B2C00D90AEA /* MC2MapsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */; };
EAF2746F2C1C6B2C00D90AEA /* MapsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */; };
EAF274712C1C6B2E00D90AEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF274702C1C6B2E00D90AEA /* Assets.xcassets */; };
Expand All @@ -16,6 +17,7 @@

/* Begin PBXFileReference section */
A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLocation.swift; sourceTree = "<group>"; };
A88329F12C71EA6100D6CC87 /* ModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalView.swift; sourceTree = "<group>"; };
EAF274692C1C6B2C00D90AEA /* MC2Maps.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MC2Maps.app; sourceTree = BUILT_PRODUCTS_DIR; };
EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MC2MapsApp.swift; sourceTree = "<group>"; };
EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -57,6 +59,7 @@
EAF5A4462C22D14600EA2907 /* Info.plist */,
EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */,
EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */,
A88329F12C71EA6100D6CC87 /* ModalView.swift */,
A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */,
EAF274702C1C6B2E00D90AEA /* Assets.xcassets */,
EAF274722C1C6B2E00D90AEA /* Preview Content */,
Expand Down Expand Up @@ -144,6 +147,7 @@
files = (
EAF2746F2C1C6B2C00D90AEA /* MapsView.swift in Sources */,
EAF2746D2C1C6B2C00D90AEA /* MC2MapsApp.swift in Sources */,
A88329F22C71EA6100D6CC87 /* ModalView.swift in Sources */,
A88329EE2C6DEBCC00D6CC87 /* MapLocation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion MC2Maps/MapLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class GeoServiceManager: NSObject, CLLocationManagerDelegate {
let locality = address.locality ?? ""
let subLocality = address.subLocality ?? ""
let subThoroughfare = address.subThoroughfare ?? ""
let fullAddress = "\(country) \(administrativeArea) \(locality) \(subLocality) \(subThoroughfare)"
let fullAddress = "\(country)\n\(administrativeArea)\n\(locality)\n\(subLocality)\n\(subThoroughfare)"


DispatchQueue.main.async {
Expand Down
20 changes: 0 additions & 20 deletions MC2Maps/MapsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ struct MapsView: View {
@State private var hasStayedAtLocation: Bool = false // 현재 위치에서 00초 이상 머물렀는지 여부
@State private var cloverCounts: (threeLeaf: Int, fourLeaf: Int) = (0, 0) // 세잎, 네잎 클로버 수


let geoServiceManager = GeoServiceManager()
let maxAnnotations = 48 // 최대 어노테이션 수
let gridSize = 6
let cellSize = 0.0001
Expand Down Expand Up @@ -157,30 +155,12 @@ struct MapsView: View {
.resizable()
.frame(width: 30,height: 30)
}
Text("북: \(annotation.coordinate.latitude)")
Text("동: \(annotation.coordinate.longitude)")
// 도로명 주소 표시
if let roadAddress = roadAddress {
Text("주소: \(roadAddress)")
} else {
Text("주소를 불러오는 중...")
.onAppear {
let location = CLLocation(latitude: annotation.coordinate.latitude,
longitude: annotation.coordinate.longitude)
geoServiceManager.getRoadAddress(for: location) { address in
self.roadAddress = address
}
}
}
Text("오늘은 이곳에서 00만큼 머물렀습니다")
// 클로버 수 표시
Text("세잎 클로버: \(cloverCounts.threeLeaf)")
Text("네잎 클로버: \(cloverCounts.fourLeaf)")
Button("Close") {
selectedSpecialAnnotation = nil
}
Spacer()

.presentationDetents([.fraction(0.1), .medium, .large])
.presentationDragIndicator(.visible)
.presentationBackgroundInteraction(.enabled)
Expand Down
100 changes: 100 additions & 0 deletions MC2Maps/ModalView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// ModalView.swift
// MC2Maps
//
// Created by Evelyn Hong on 8/18/24.
//

import SwiftUI
import MapKit
import CoreLocation

struct ModalView: View {
let annotation: MKPointAnnotation
@State private var roadAddress: String? = nil // 주소를 저장할 @State 변수

let stayDuration: [(String, String)]
let items: [(String, String)]

// GeoServiceManager 인스턴스 추가
private let geoServiceManager = GeoServiceManager()

init(annotation: MKPointAnnotation, stayDuration: String) {
self.annotation = annotation
self.stayDuration = [("머문시간", stayDuration)]
self.items = [
("좌표", "\(annotation.coordinate.latitude)°, 동 \(annotation.coordinate.longitude)°")
]
}

var body: some View {
List {
// 첫 번째 섹션 - '머무른 시간'
Section(header: Text("세부사항")
.font(.title2)
.fontWeight(.semibold)
.foregroundStyle(Color.black)
.padding(.vertical, 10)
.padding(.leading, -10)
) {
ForEach(stayDuration, id: \.0) { item in
VStack(alignment: .leading) {
Text(item.0)
.font(.system(size: 17))
.foregroundColor(Color(UIColor.systemGray2))
Text(item.1)
.foregroundColor(Color.green)
}
}
}
.textCase(nil)

// 두 번째 섹션 - '주소 및 좌표'
Section {
VStack(alignment: .leading) {
if let roadAddress = roadAddress {
Text("주소")
.font(.system(size: 17))
.foregroundColor(Color(UIColor.systemGray2))
Text(roadAddress)
} else {
Text("주소")
.font(.system(size: 17))
.foregroundColor(Color(UIColor.systemGray2))
Text("주소를 불러오는 중...")
.onAppear {
let location = CLLocation(latitude: annotation.coordinate.latitude,
longitude: annotation.coordinate.longitude)
geoServiceManager.getRoadAddress(for: location) { address in
self.roadAddress = address
}
}
}
}

ForEach(items, id: \.0) { item in
VStack(alignment: .leading) {
Text(item.0)
.font(.system(size: 17))
.foregroundColor(Color(UIColor.systemGray2))
Text(item.1)
}
}
}
}
.scrollDisabled(true)
.listSectionSpacing(22)

}
}

struct ModalView_Previews: PreviewProvider {
static var previews: some View {
let exampleAnnotation = MKPointAnnotation()
exampleAnnotation.coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)

return ModalView(annotation: exampleAnnotation, stayDuration: "2시간 30분")
}
}


0 comments on commit 40758e6

Please sign in to comment.