Using Swift5.5, iOS15.0.1,
To create a PageView is still not that simple in SwiftUI - even in Fall 2021.
Apple gives us the possibility to mis-use a TabView with a special modifier in order to create a PageView
The modifier is called .tabViewStyle(.page(indexDisplayMode: .always))
and it works somewhat until you rotate the phone from Portrait to Landscape.
Apple somehow did not think of Portrait-to-Landscape rotation with this API.
ROTATING THE PHONE MESSES UP THE PAGE-INDEX COMPLETELY !!
Below is the entire code of this example. Try yourself rotating the phone.
See video:
What do you need to to in order to keep the index intact after rotation ?
--> And please, I don't mean to re-gain the index. I am speaking about a nice, smooth rotation around the current index (not some sort of hacky workaround where the index needs to be stored and after rotation re-assigned again...)
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
ScrollView(.init()) {
TabView {
Text("Hello 1")
Text("Hello 2")
Text("Hello 3")
Text("Hello 4")
}
.id(UUID())
.tabViewStyle(.page(indexDisplayMode: .always))
}
.ignoresSafeArea()
.transition(.move(edge: .bottom))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}