Код: Выделить всё
import SwiftUI
import MapKit
struct DraggableSplitMapView: View {
@State private var mapRegion = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
)
@State private var mapHeight: CGFloat = 300
@GestureState private var dragOffset: CGSize = .zero
var body: some View {
NavigationView {
GeometryReader { geometry in
VStack(spacing: 0) {
Map(coordinateRegion: $mapRegion)
.frame(height: calculateMapHeight(geometry: geometry))
// Drag handle
ZStack {
Color.clear.frame(height: 12)
Capsule()
.fill(Color.secondary.opacity(0.5))
.frame(width: 40, height: 6)
}
.gesture(
DragGesture()
.updating($dragOffset) { value, state, _ in
state = value.translation
}
.onEnded { value in
let newHeight = self.mapHeight + value.translation.height
// Clamp the height from getting too big or small.
self.mapHeight = max(100, min(geometry.size.height - 150, newHeight))
}
)
// Dummy list
List(0.. CGFloat {
let proposedHeight = self.mapHeight + self.dragOffset.height
// Ensure the height stays within reasonable bounds during the drag.
return max(100, min(geometry.size.height - 150, proposedHeight))
}
}
struct DraggableSplitMapView_Previews: PreviewProvider {
static var previews: some View {
DraggableSplitMapView()
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... zing-issue
Мобильная версия