Swift监听屏幕旋转

NSNotificationCenter.defaultCenter().addObserver(self, selector: "receiverNotification", name: UIDeviceOrientationDidChangeNotification, object: nil)


func receiverNotification(){
        let orient = UIDevice.currentDevice().orientation
        switch orient {
        case .Portrait :
            print("屏幕正常竖向")
            break
        case .PortraitUpsideDown:
            print("屏幕倒立")
            break
        case .LandscapeLeft:
            print("屏幕左旋转")
            break
        case .LandscapeRight:
            print("屏幕右旋转")
            break
        default:
            break
        }
    }


你可能感兴趣的:(Swift)