【发布时间】:2019-05-14 01:43:15
【问题描述】:
如何在不自动旋转的情况下设置指定的页面旋转?我发现只有当var shouldAutorotate返回yes时屏幕才能旋转,但我不想自动这样做,我想自己控制旋转的时刻
【问题讨论】:
-
我设置了VC的静态变量canRotate,需要旋转的时候设置为true,旋转完成后设置为fals。
override var shouldAutorotate: Bool { return canRotate } -
canRotate在收到UIDevice.orientationDidChangeNotification后设置为false,我发现在iphoneX,iOS 12.1的某个时候屏幕不能旋转orientationDidChangeNotification来了(虽然这是小概率事件) -
旋转屏幕代码:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation") -
我在旋转代码之前解决了它:
if !UIDevice.current.isGeneratingDeviceOrientationNotifications { UIDevice.current.beginGeneratingDeviceOrientationNotifications() }
标签: ios swift rotation screen shouldautorotate