iOS, Swift/Tip, Bug, Swift Error
Swift ) iOS16 강제 화면 회전 대응 - EEYatHo iOS
EEYatHo
2022. 10. 4. 12:00
반응형
Scene의 화면회전 제어 로직이 변경되면서,
기존에 사용하던 UIDevice 방식은 deprecated 되었다.
// is deprecated
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
해당 방식으로 강제 화면 회전시, 친절하게 아래와 같은 에러가 발생한다.
( UIWindowScene.requestGeometryUpdate 를 사용해달라는 말. )
새로 사용해야 될 함수 :
적용 코드 :
/// 화면 가로로 바꾸기
if #available(iOS 16.0, *) {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeRight))
} else {
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}