【问题标题】:Orientation Lock of UIViewController - Xcode - Swift [duplicate]UIViewController 的方向锁定 - Xcode - Swift [重复]
【发布时间】:2015-04-07 05:29:49
【问题描述】:

如何以编程方式强制我的视图控制器保持纵向模式?我已经为我的 iOS 应用程序创建了一个共享扩展,我需要我的视图始终保持纵向模式,尽管设备的方向。下面的覆盖方法不起作用:

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientation.Portrait.rawValue)
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.Portrait
}

override func shouldAutorotate() -> Bool {
    return false
}

【问题讨论】:

  • 分享扩展出现在另一个应用程序中,而不是您的应用程序中。您的代码对该应用的方向没有发言权。
  • Matt,我明白了,但是扩展有自己的视图控制器,应该可以控制吧?

标签: ios cocoa-touch swift uiviewcontroller


【解决方案1】:

您可以在viewWillApear使用此代码

 let value = UIInterfaceOrientation.Portrait.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 2015-08-06
    • 2015-01-16
    • 2011-04-09
    相关资源
    最近更新 更多