Using Swift 5.3.2, Xcode 12.4, iOS 14.4,
I am trying to make a simple Page-TabView in SwiftUI (see below code-excerpt).
When rotating to Landscape or back to Portrait, there is a problem (see video):
Whenever I rotate my iPhone, the TabView "jumps" to a random tab-number.
Why is this ?
What can I do make the TabView keep the current tab-number when rotating ?
(I am using an iPhoneX)
There seem more issues with the new iOS14 TabView's PageControl function as decribed here. (Maybe the "random tab-number" when rotating the device is related to the layout-issue described)
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
TabView {
Text("1")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.pink)
Text("2")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.yellow)
Text("3")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.green)
Text("4")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.blue)
}
.tabViewStyle(PageTabViewStyle())
}
}
}