版权声明: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()
}