【发布时间】:2016-09-06 15:18:06
【问题描述】:
我正在使用这些代码行检测设备方向:
UIDevice.currentDevice().orientation.isPortrait.boolValue
UIDevice.currentDevice().orientation.isLandscape.boolValue
我用这段代码检测它是否是 iPad:
userInterfaceIdiom == .Pad
我在commonInit() 函数中使用了这段代码,该函数在Init() 函数中调用。当我在 iPad 上执行我的代码时,前两行都返回 false,这是不正确的,其中一个应该是 true。第三行工作正常。
如果我在其他函数中使用该代码,例如supportedInterfaceOrientations(),它可以正常工作。你知道可能是什么问题吗?
【问题讨论】:
-
init()...init()...,我们在说谁的init()方法? -
我尝试使用代码行的类的 init() 方法。我想用取决于 iPad 方向的值来初始化类
-
@holex 要求提供类的 type ......它是 UIViewController 吗?在构建此类之前,应用程序是否已完全初始化并告诉 AppDelegate 它已准备好?
标签: ios swift ipad landscape-portrait