You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import SwiftUI
// MARK: -
struct LocationInputView: View {
@Binding var latitude: String
@Binding var longitude: String
@Binding var locationName: String
@FocusState var focusedField: LocationField?
//
enum LocationField: Hashable {
case latitude, longitude, locationName
}
var body: some View {
VStack(spacing: 16) {
//
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("位置名称")
.font(.subheadline)
.foregroundColor(.primary)
Spacer()
}
TextField("例如:纽约时代广场", text: $locationName)
.textFieldStyle(RoundedBorderTextFieldStyle())
.focused($focusedField, equals: .locationName)
}
//
HStack(spacing: 12) {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("纬度")
.font(.subheadline)
.foregroundColor(.primary)
Text("*")
.foregroundColor(.red)
Spacer()
}
TextField("40.7589", text: $latitude)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.decimalPad)
.focused($focusedField, equals: .latitude)
}
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("经度")
.font(.subheadline)
.foregroundColor(.primary)
Text("*")
.foregroundColor(.red)
Spacer()
}
TextField("-73.9851", text: $longitude)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.decimalPad)
.focused($focusedField, equals: .longitude)
}
}
//
VStack(alignment: .leading, spacing: 8) {
HStack {
Image(systemName: "info.circle")
.font(.caption)
.foregroundColor(.blue)
Text("坐标格式说明")
.font(.caption)
.foregroundColor(.primary)
Spacer()
}
Text("• 纬度范围:-90 到 90\n• 经度范围:-180 到 180\n• 使用小数点分隔40.7589")
.font(.caption)
.foregroundColor(.secondary)
.lineLimit(nil)
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color.blue.opacity(0.1))
)
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("完成") {
focusedField = nil
}
.foregroundColor(.blue)
.font(.system(size: 16, weight: .medium))
}
}
}
}
#Preview {
LocationInputView(
latitude: .constant(""),
longitude: .constant(""),
locationName: .constant("")
)
}