Skip to content

Commit

Permalink
Chore:wrench:: #32 add animation
Browse files Browse the repository at this point in the history
- 검색한 좌표로 이동할 때, 순간이동하듯 넘어가지 않고 애니메이션으로 자연스럽게 이동하도록 변경
  • Loading branch information
taek0622 committed Jun 13, 2023
1 parent add7d24 commit 0906d0a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Nav/View/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import MapKit
import SwiftUI
struct MapView: View {
@ObservedObject var addressSearcher = AddressSearcher()
@ObservedObject var locationManager = LocationManager()

// 서울 좌표
@State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.5666791, longitude: 126.9782914), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
Expand All @@ -23,13 +23,15 @@ struct MapView: View {
data in MapMarker(coordinate: data.coordinate)
}

if addressSearcher.searchQuery != "" {
List(addressSearcher.completions) { completion in
if locationManager.searchQuery != "" {
List(locationManager.completions) { completion in
Button {
addressSearcher.loadAddressCoordinate(completion) { coordinate in
region = MKCoordinateRegion(center: coordinate, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
locationManager.loadAddressCoordinate(completion) { location in
withAnimation {
region = location
}
}
addressSearcher.searchQuery = ""
locationManager.searchQuery = ""
} label: {
VStack(alignment: .leading) {
Text(completion.title)
Expand All @@ -45,7 +47,7 @@ struct MapView: View {
}
.navigationTitle("NAV")
.searchable(
text: $addressSearcher.searchQuery,
text: $locationManager.searchQuery,
placement: .navigationBarDrawer,
prompt: "검색"
)
Expand Down

0 comments on commit 0906d0a

Please sign in to comment.