- Реализация AppDelegate < /code>, < /p>
}
Код: Выделить всё
class AppDelegate: NSObject, UIApplicationDelegate { static var orientationLock = UIInterfaceOrientationMask.portrait //By default you want all your views to rotate freely func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return AppDelegate.orientationLock } < /code> } < /p> < /li> < /ol> Но оно устанавливает все приложение на ориентацию портрета, чем просто представление. < /p> Методы ориентации на основе на основе uidevice Методы установки: больше не работают, и это неясно, как их можно использовать для блокировки ориентации из одного представления. Вид сначала вращается, а затем не работает, и в процессе вращается вся иерархия представления, а не только рассматриваемое представление. < /P> SampleBufferView(viewModel: camera, sampleBuffer: latestSample) .aspectRatio(verticalSizeClass == .regular ? 9.0/16.0 : 16.0/9.0, contentMode: .fit) .onAppear { if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene { scene.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait)) { error in // Handle denial of request. } } } .onGeometryChange(for: CGSize.self, of: { proxy in proxy.size }, action: { newValue in requestOrientations(.portrait) }) private func requestOrientations(_ orientations: UIInterfaceOrientationMask) { if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene { scene.requestGeometryUpdate(.iOS(interfaceOrientations: orientations)) { error in // Handle denial of request. } }
Подробнее здесь: https://stackoverflow.com/questions/794 ... o-portrait