Same here - in my case it is even more than one Tab jump that the rotation to landscape or back to portrait causes.
Coud it be because the TabView-frame is much wider than tall ? But shouldn't the TabView rotation take care of this.
My rotation is made as follows:
Swift
struct DeviceRotationViewModifier: ViewModifier {
let action: (UIDeviceOrientation) - Void
func body(content: Content) - some View {
content
.onAppear()
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
action(UIDevice.current.orientation)
}
}
}
Swift
extension View {
func onRotate(perform action: @escaping (UIDeviceOrientation) - Void) - some View {
self.modifier(DeviceRotationViewModifier(action: action))
}
}
And finally, where I rotate my TabView:
Swift
TabView(selection: self.$selectedTab) {
...
}
.tabViewStyle(PageTabViewStyle())
.onRotate { _ in
print(selectedTab)
}
Any solution to this problem is highly appreciated, thank you.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: