Перестановка просмотров на viewWillTransition

0
задан rmaddy 19 January 2019 в 05:40
поделиться

1 ответ

Вы можете обнаружить вращение устройства указанным ниже способом и переместить ваши предметы.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    NotificationCenter.default.addObserver(self, selector: #selector(deviceRotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}

override func viewWillDisappear(_ animated: Bool) {
    NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}

func deviceRotated(){
    if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) {
        print("Landscape")
        // Resize other things
    }
    if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) {
        print("Portrait")
        // Resize other things
    }
}
0
ответ дан Arash Etemad 19 January 2019 в 05:40
поделиться
Другие вопросы по тегам:

Похожие вопросы: