Attempt to fix orientation lock on iOS 16

This commit is contained in:
Arkadiusz Fal 2022-11-11 14:25:56 +01:00
parent a3ba1cb6df
commit 99e20f54a2
2 changed files with 8 additions and 4 deletions

View File

@ -342,7 +342,10 @@ struct PlayerControls: View {
if player.lockedOrientation.isNil {
let orientationMask = OrientationTracker.shared.currentInterfaceOrientationMask
player.lockedOrientation = orientationMask
Orientation.lockOrientation(orientationMask)
let orientation = OrientationTracker.shared.currentInterfaceOrientation
Orientation.lockOrientation(orientationMask, andRotateTo: .landscapeLeft)
// iOS 16 workaround
Orientation.lockOrientation(orientationMask, andRotateTo: orientation)
} else {
player.lockedOrientation = nil
Orientation.lockOrientation(.allButUpsideDown, andRotateTo: OrientationTracker.shared.currentInterfaceOrientation)

View File

@ -30,9 +30,6 @@ struct Orientation {
logger.info("rotating to \(orientationString)")
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
if #available(iOS 16, *) {
guard let windowScene = SafeArea.scene else { return }
let rotateOrientationMask = rotateOrientation == .portrait ? UIInterfaceOrientationMask.portrait :
@ -43,6 +40,10 @@ struct Orientation {
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: rotateOrientationMask)) { error in
print("denied rotation \(error)")
}
}
} else {
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
}
UINavigationController.attemptRotationToDeviceOrientation()
}
}