Но у моего кода есть некоторые проблемы.
- Когда FirstView(). NavigationDestination загружается, мой NextView ведет себя странно.
- В NextView(), когда я смахиваю по экрану в направлении x, NextView() сдвигает фазу экрана в направлении x (влево).
@State var isNextView = false
var body: some View {
NavigationStack {
VStack {
Button {
isNextView.toggle()
} label: {
Text("go next page")
}
}
.navigationDestination(isPresented: $isNextView, destination: {
NextView()
.navigationBarBackButtonHidden(true)
})
}
}
}
struct NextView: View {
let width = UIScreen.main.bounds.width
let height = UIScreen.main.bounds.height
let colors: [Color] = [Color.yellow, Color.blue, Color.green, Color.red, Color.pink]
@State var selection: Int = 0
@State var opacity = 1.0
@Environment(\.dismiss) private var dismiss
var body: some View {
NavigationStack {
ZStack {
TabView(selection: $selection) {
ForEach(Array(0 ..< colors.count), id: \.self) { index in
VStack {
Rectangle()
.frame(width: width, height: height)
.foregroundColor(colors[index])
}
.rotationEffect(Angle(degrees: -90), anchor: .center)
.frame(width: width, height: height)
}
.edgesIgnoringSafeArea(.all)
.ignoresSafeArea()
}
.rotationEffect(Angle(degrees: 90), anchor: .center)
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.frame(width: height, height: width, alignment: .center)
.toolbarBackground(.hidden, for: .navigationBar)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
dismiss()
} label: {
Image(systemName: "chevron.left")
.imageScale(.large)
.foregroundColor(.black)
}
}
}
}
.toolbarBackground(.hidden, for: .navigationBar)
.frame(width: width, height: height)
.edgesIgnoringSafeArea(.all)
.ignoresSafeArea()
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... tioneffect
Мобильная версия