В моем представлении о подробностях 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_I ... _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
update
после некоторой отладки я смог сузить проблему до этой части кода в родительском представлении
.navigationTitle("vehicles")
.searchable(text: $searchField, isPresented: $searchVisible, placement: .navigationBarDrawer, prompt: "search")
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button() { searchVisible = true } label: { Image(systemName: "magnifyingglass") }
Menu {
Picker(selection: $vehicleState) {
ForEach(VehicleState.allCases, id:\.self) { choice in
Text(LocalizedStringKey(choice.rawValue))
}
} label: {
Text("Select a state")
}
} label: {
if vehicleState == .all {
Image(systemName: "line.3.horizontal.decrease.circle")
} else {
Image(systemName: "line.3.horizontal.decrease.circle.fill")
}
}
}
}
< /code>
Полный код rootview < /p>
NavigationStack {
List(appState.vehicles.filter {
(
$0.model.lowercased().contains(searchField.lowercased()) ||
$0.plate.lowercased().contains(searchField.lowercased()) ||
$0.brand.lowercased().contains(searchField.lowercased()) ||
$0.driverName.lowercased().contains(searchField.lowercased()) ||
(vehicleLocations[$0.id]?.lowercased().contains(searchField.lowercased()) ?? false) ||
searchField.isEmpty
) && (
vehicleState == .all ||
(vehicleState == .off && !$0.ignition) ||
(vehicleState == .running && $0.ignition && $0.speed >= 5) ||
(vehicleState == .idle && $0.ignition && $0.speed < 5)
)
}) { vehicle in
NavigationLink(destination: VehiclePositionView(vehicle: vehicle)) {
VehicleCell(vehicle: vehicle, locatedCallback: {
vehicleLocations[vehicle.id] = $0
})
}
}
.safeAreaInset(edge: .bottom) {
Spacer()
.frame(height: navbarHeight + 10)
}
.navigationBarTitleDisplayMode(.large)
.navigationTitle("vehicles")
.searchable(text: $searchField, isPresented: $searchVisible, placement: .navigationBarDrawer, prompt: "search")
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button() { searchVisible = true } label: { Image(systemName: "magnifyingglass") }
Menu {
Picker(selection: $vehicleState) {
ForEach(VehicleState.allCases, id:\.self) { choice in
Text(LocalizedStringKey(choice.rawValue))
}
} label: {
Text("Select a state")
}
} label: {
if vehicleState == .all {
Image(systemName: "line.3.horizontal.decrease.circle")
} else {
Image(systemName: "line.3.horizontal.decrease.circle.fill")
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... in-swiftui
Пользовательский заголовок в навигационной панели в Swiftui ⇐ IOS
Программируем под IOS
-
Anonymous
1741608931
Anonymous
В моем представлении о подробностях 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
[b] update [/b]
после некоторой отладки я смог сузить проблему до этой части кода в родительском представлении
.navigationTitle("vehicles")
.searchable(text: $searchField, isPresented: $searchVisible, placement: .navigationBarDrawer, prompt: "search")
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button() { searchVisible = true } label: { Image(systemName: "magnifyingglass") }
Menu {
Picker(selection: $vehicleState) {
ForEach(VehicleState.allCases, id:\.self) { choice in
Text(LocalizedStringKey(choice.rawValue))
}
} label: {
Text("Select a state")
}
} label: {
if vehicleState == .all {
Image(systemName: "line.3.horizontal.decrease.circle")
} else {
Image(systemName: "line.3.horizontal.decrease.circle.fill")
}
}
}
}
< /code>
Полный код rootview < /p>
NavigationStack {
List(appState.vehicles.filter {
(
$0.model.lowercased().contains(searchField.lowercased()) ||
$0.plate.lowercased().contains(searchField.lowercased()) ||
$0.brand.lowercased().contains(searchField.lowercased()) ||
$0.driverName.lowercased().contains(searchField.lowercased()) ||
(vehicleLocations[$0.id]?.lowercased().contains(searchField.lowercased()) ?? false) ||
searchField.isEmpty
) && (
vehicleState == .all ||
(vehicleState == .off && !$0.ignition) ||
(vehicleState == .running && $0.ignition && $0.speed >= 5) ||
(vehicleState == .idle && $0.ignition && $0.speed < 5)
)
}) { vehicle in
NavigationLink(destination: VehiclePositionView(vehicle: vehicle)) {
VehicleCell(vehicle: vehicle, locatedCallback: {
vehicleLocations[vehicle.id] = $0
})
}
}
.safeAreaInset(edge: .bottom) {
Spacer()
.frame(height: navbarHeight + 10)
}
.navigationBarTitleDisplayMode(.large)
.navigationTitle("vehicles")
.searchable(text: $searchField, isPresented: $searchVisible, placement: .navigationBarDrawer, prompt: "search")
.toolbar {
ToolbarItemGroup(placement: .topBarTrailing) {
Button() { searchVisible = true } label: { Image(systemName: "magnifyingglass") }
Menu {
Picker(selection: $vehicleState) {
ForEach(VehicleState.allCases, id:\.self) { choice in
Text(LocalizedStringKey(choice.rawValue))
}
} label: {
Text("Select a state")
}
} label: {
if vehicleState == .all {
Image(systemName: "line.3.horizontal.decrease.circle")
} else {
Image(systemName: "line.3.horizontal.decrease.circle.fill")
}
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79492885/custom-title-in-navigation-bar-in-swiftui[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия