Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios '的实例成员;当前设备';不能在类型上使用_Ios_Xcode_Swift_Orientation_Device Orientation - Fatal编程技术网

Ios '的实例成员;当前设备';不能在类型上使用

Ios '的实例成员;当前设备';不能在类型上使用,ios,xcode,swift,orientation,device-orientation,Ios,Xcode,Swift,Orientation,Device Orientation,我正在为IOS制作视频播放器&希望检查设备何时旋转,何时旋转,我的代码将使视频播放器全屏显示,但在上出现以下错误-“实例成员”currentDevice不能用于类型“viewController” var currentDevice: UIDevice = UIDevice.currentDevice() var orientation: UIDeviceOrientation = currentDevice.orientation //error here if orientation.is

我正在为IOS制作视频播放器&希望检查设备何时旋转,何时旋转,我的代码将使视频播放器全屏显示,但在上出现以下错误-“实例成员”currentDevice不能用于类型“viewController”

var currentDevice: UIDevice = UIDevice.currentDevice()
var orientation: UIDeviceOrientation = currentDevice.orientation //error here

if orientation.isLandscape {

}

if orientation.isPortrait {

}
我试着用多种东西来替换currentDevice,我也试着把
放在它下面,还有
self.
我几天前就开始和Swift合作了,有人能给我指出正确的方向吗

您可以尝试以下代码:)


我决定在项目设置中强制应用程序进入横向模式。

您将发布的代码放在viewcontroller类的何处?将代码放在viewDidLoad()或函数中。变量放在我的viewDidLoad()上方;谢谢,这解决了我的问题d您可以签入viewWillAppear()。请您解释一下您正在做什么,以及为什么这与改进答案不同。
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator){
    if UIDevice.currentDevice().orientation.isLandscape.boolValue{
        print("Device is in Landscape Mode")
} else {
        print(" Device is in Portrait mode ")
    }
}