Anonymous
Пользовательский заголовок в навигационной панели в Swiftui
Сообщение
Anonymous » 10 мар 2025, 12:43
В моем представлении о подробностях Swiftui у меня есть этот код (часть его) < /p>
Код: Выделить всё
import SwiftUI
import MapKit
import Kingfisher
import BottomSheet
struct VehiclePositionView: View {
@Environment(\.isPresented) var isPresented
@Environment(\.colorScheme) var colorScheme
@EnvironmentObject var themeProvider: ThemeProvider
@State var vehicle: VehicleModel
@State private var bottomSheetPosition: BottomSheetPosition = .dynamicBottom
@State private var cameraPosition = MapCameraPosition.region(
MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 0, longitude: 0),
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
)
)
let span: (CGFloat, CGFloat) = (0.005, 0.005)
let imgUrl = URL(string: "https://clientes.gesfrota.pt/Gesfrota_Images/1/Viaturas/viatura_14563.jpg")!
var body: some View {
Map(position: $cameraPosition) {
Annotation(vehicle.plate, coordinate: location) {
Image(systemName: "car")
.foregroundColor(themeProvider.accentColor)
.background(
Circle()
.fill(Color.white)
.frame(width: 30, height: 30)
.shadow(color: getVehicleStatusColor(for: vehicle), radius: 3)
)
}
}
.mapStyle(.standard(elevation: .realistic, showsTraffic: true))
.onAppear {
NotificationCenter.notify(.toggleBottomBar)
cameraPosition = .region(
MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: vehicle.latitude, longitude: vehicle.longitude),
span: MKCoordinateSpan(latitudeDelta: span.0, longitudeDelta: span.1)
)
)
}
.onChange(of: isPresented) {
if !isPresented {
NotificationCenter.notify(.toggleBottomBar)
}
}
.toolbar {
ToolbarItem(placement: .principal) {
VStack(spacing: 3) {
ZStack {
KFImage(imgUrl)
.fade(duration: 0.25)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(
color: colorScheme == .dark ? Color.white.opacity(0.7) : Color.black.opacity(0.3),
radius: 5
)
Circle()
.fill(getVehicleStatusColor(for: vehicle))
.frame(width: 12, height: 12)
.offset(x: 18, y: 20)
}
Text(vehicle.plate)
Text("\(vehicle.brand) \(vehicle.model)")
.font(.footnote)
.foregroundStyle(themeProvider.secondary)
}
//.padding(.top, 50)
}
}
.toolbarBackground(.thinMaterial, for: .navigationBar)
.toolbarRole(.editor)
.toolbarVisibility(.visible, for: .navigationBar)
.bottomSheet(bottomSheetPosition: $bottomSheetPosition, switchablePositions: [.dynamicTop, .dynamicBottom]) {
VStack(alignment: .leading, spacing: 8) {
Text(vehicle.plate)
.font(.title2)
.bold()
.foregroundStyle(themeProvider.primary)
Text("\(vehicle.brand) \(vehicle.model)")
.font(.callout)
.foregroundStyle(themeProvider.secondary)
}
.padding(.horizontal)
} mainContent: {
}
}
private var location: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: vehicle.latitude, longitude: vehicle.longitude)
}
}
Я ожидал получить следующий вывод, и это именно то, что я получаю в предварительном просмотре Xcode
nw at at nat we simulator we simulator/nw at at nat we simulator we simulator/preaulator. />
Как вы можете видеть, когда начинается переход, он появляется, но когда анимация заканчивается, я не заканчивает его, не используется, я не заканчивает его, не используется, я не заканчивает анимацию. На деталях (это представление) в этом посте представлена конфигурация панели инструментов/Navbar. Я нацелен на iOS 18
Подробнее здесь:
https://stackoverflow.com/questions/794 ... in-swiftui
1741599833
Anonymous
В моем представлении о подробностях Swiftui у меня есть этот код (часть его) < /p> [code]import SwiftUI import MapKit import Kingfisher import BottomSheet struct VehiclePositionView: View { @Environment(\.isPresented) var isPresented @Environment(\.colorScheme) var colorScheme @EnvironmentObject var themeProvider: ThemeProvider @State var vehicle: VehicleModel @State private var bottomSheetPosition: BottomSheetPosition = .dynamicBottom @State private var cameraPosition = MapCameraPosition.region( MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 0, longitude: 0), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) ) ) let span: (CGFloat, CGFloat) = (0.005, 0.005) let imgUrl = URL(string: "https://clientes.gesfrota.pt/Gesfrota_Images/1/Viaturas/viatura_14563.jpg")! var body: some View { Map(position: $cameraPosition) { Annotation(vehicle.plate, coordinate: location) { Image(systemName: "car") .foregroundColor(themeProvider.accentColor) .background( Circle() .fill(Color.white) .frame(width: 30, height: 30) .shadow(color: getVehicleStatusColor(for: vehicle), radius: 3) ) } } .mapStyle(.standard(elevation: .realistic, showsTraffic: true)) .onAppear { NotificationCenter.notify(.toggleBottomBar) cameraPosition = .region( MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: vehicle.latitude, longitude: vehicle.longitude), span: MKCoordinateSpan(latitudeDelta: span.0, longitudeDelta: span.1) ) ) } .onChange(of: isPresented) { if !isPresented { NotificationCenter.notify(.toggleBottomBar) } } .toolbar { ToolbarItem(placement: .principal) { VStack(spacing: 3) { ZStack { KFImage(imgUrl) .fade(duration: 0.25) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 50, height: 50) .clipShape(Circle()) .shadow( color: colorScheme == .dark ? Color.white.opacity(0.7) : Color.black.opacity(0.3), radius: 5 ) Circle() .fill(getVehicleStatusColor(for: vehicle)) .frame(width: 12, height: 12) .offset(x: 18, y: 20) } Text(vehicle.plate) Text("\(vehicle.brand) \(vehicle.model)") .font(.footnote) .foregroundStyle(themeProvider.secondary) } //.padding(.top, 50) } } .toolbarBackground(.thinMaterial, for: .navigationBar) .toolbarRole(.editor) .toolbarVisibility(.visible, for: .navigationBar) .bottomSheet(bottomSheetPosition: $bottomSheetPosition, switchablePositions: [.dynamicTop, .dynamicBottom]) { VStack(alignment: .leading, spacing: 8) { Text(vehicle.plate) .font(.title2) .bold() .foregroundStyle(themeProvider.primary) Text("\(vehicle.brand) \(vehicle.model)") .font(.callout) .foregroundStyle(themeProvider.secondary) } .padding(.horizontal) } mainContent: { } } private var location: CLLocationCoordinate2D { return CLLocationCoordinate2D(latitude: vehicle.latitude, longitude: vehicle.longitude) } } [/code] Я ожидал получить следующий вывод, и это именно то, что я получаю в предварительном просмотре Xcode nw at at nat we simulator we simulator/nw at at nat we simulator we simulator/preaulator. /> Как вы можете видеть, когда начинается переход, он появляется, но когда анимация заканчивается, я не заканчивает его, не используется, я не заканчивает его, не используется, я не заканчивает анимацию. На деталях (это представление) в этом посте представлена конфигурация панели инструментов/Navbar. Я нацелен на iOS 18 Подробнее здесь: [url]https://stackoverflow.com/questions/79492885/custom-title-in-navigation-bar-in-swiftui[/url]