Вот упрощенная версия кода: < /p>
Код: Выделить всё
import SwiftUI
struct ContentView: View {
@Environment(\.dismiss) var dismiss
@State var isExpanded = false
var body: some View {
NavigationStack {
Color.red
.toolbar(isExpanded ? .visible : .hidden)
.overlay(alignment: .topTrailing) {
Image(systemName: isExpanded ? "chevron.up.circle" : "chevron.down.circle")
.padding()
.background {
RoundedRectangle(cornerRadius: 20)
.fill(Color.gray.opacity(0.5))
}
.padding()
.onTapGesture {
isExpanded.toggle()
}
.animation(.default, value: isExpanded)
}
.toolbar {
ToolbarItem(placement: .navigation) {
Button {
dismiss()
} label: {
Image(systemName: "chevron.backward")
}
}
}
}
}
}
#Preview {
ContentView()
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ling-state