2016-02-05 54 views
0

我正在为IOS制作视频播放器&想要检查设备何时旋转,何时它是我的代码将使视频播放器全屏,但是我是收到以下错误 - “实例成员“currentDevice的viewController‘'currentDevice'的实例成员不能用于类型

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

if orientation.isLandscape { 

} 

if orientation.isPortrait { 

} 

我已经试过的东西多,以取代currentDevice,我也试图把_下,它不能在使用类型’和也是self.几天前我开始和Swift一起工作,请问有谁能指出我正确的方向?

I've found the code here.

+1

你在哪里把你的viewcontroller类的发布代码? – Surely

+1

将代码放在viewDidLoad()或函数中。 –

+0

上面的变量我的viewDiDLoad();功能 – Gerwin

回答

0

我决定强制应用到风景模式在项目设置。

0

你可以试试这个代码:)

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 ") 
    } 
} 
+1

你能解释你在做什么,为什么这是不同的,以改善答案。 –

相关问题