Поворот iPad в альбомную ориентацию

#ipad #rotation #uikit #landscape #portrait

#iPad #поворот #uikit #альбомная ориентация #портрет

Вопрос:

Использование iOS14.1, Swift5.3,

Я пытаюсь повернуть свой iPad из книжной ориентации в альбомную. Однако в альбомном режиме вид с одной стороны черный (см. Видео).

Что мне нужно сделать, чтобы повернуть iPad ?

введите описание изображения здесь

     open override var shouldAutorotate: Bool {
        return true
    }
    
    open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        
        super.viewWillTransition(to: size, with: coordinator)

        coordinator.animate(alongsideTransition: { (context) in
            guard let windowInterfaceOrientation = self.windowInterfaceOrientation else { return }

            if windowInterfaceOrientation.isLandscape {
                // activate landscape changes
                print("landscape now")
                print(UIScreen.main.bounds.height)
                print(UIScreen.main.bounds.width)
                self.view.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
                self.view.setNeedsLayout()
                self.view.layoutSubviews()
            } else {
                // activate portrait changes
                print("portrait now")
                print(UIScreen.main.bounds.height)
                print(UIScreen.main.bounds.width)
                self.view.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
                self.view.setNeedsLayout()
                self.view.layoutSubviews()
            }
        })
    }

    private var windowInterfaceOrientation: UIInterfaceOrientation? {
        if #available(iOS 13.0, *) {
            return UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
        } else {
            return UIApplication.shared.statusBarOrientation
        }
    }
  

Комментарии:

1. Вы должны использовать size (который передается функции) вместо UIScreen.main.bounds

2. хорошо, я попробую — спасибо