iOS之检测模拟器在各个方向上的切换(Swift 4.2)

版权声明:Created by 影子传说 // Copyright © 2018年 影子传说. All rights reserved. https://blog.csdn.net/jaydneg23333/article/details/82823956
import UIKit

class ViewController: UIViewController {

    fileprivate func addImageView() {
//         Do any additional setup after loading the view, typically from a nib.
                NotificationCenter.default.addObserver(self, selector: #selector(ViewController.orientationChanged(_:)), name: UIDevice.orientationDidChangeNotification, object:nil)
                    }
            @objc func orientationChanged(_ notification: Notification){
                let device = UIDevice.current
                switch device.orientation
                {
                case .portrait:
                    print("面向设备保持垂直,home键位于下部")
                case .portraitUpsideDown:
                    print("面向设备保持垂直,home键位于上部")
                case .landscapeLeft:
                    print("面向设备保持水平,home键位于右侧")
                case .landscapeRight:
                    print("面向设备保持水平,home键位于左侧")
                case .faceUp:
                        print("设备平放,home键朝上")
                case .faceDown:
                        print("设备平放,home键朝下")
                case .unknown:
                        print("方向未知")
                }
        
        
    }


    override func viewDidLoad() {
        super.viewDidLoad()
         addImageView()
   }

猜你喜欢

转载自blog.csdn.net/jaydneg23333/article/details/82823956
4.2