2015-04-07 66 views
0

如何强制我的视图控制器以编程方式保持纵向模式?我为我的iOS应用创建了一个共享扩展,我需要我的视图始终保持纵向模式,尽管设备的方向不变。下面的替代方法不起作用:UIViewController的方向锁定 - Xcode - Swift

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

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

出现A股延长使用此代码,不是你的。您的代码在该应用的方向上没有发言权。 – matt

+0

马特,我明白,但扩展有它自己的视图控制器,它应该能够控制这个权利? –

回答

-1

您可以在其他应用中viewWillApear

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

我试过这个。 –