我的应用程序允许所有四种方向,但是rootviewcontroller应该只允许纵向方向。
我覆盖了rootviewcontroller中的supportedInterfaceOrientations方法,但是如果在应用程序启动时设备处于横向,那么视图控制器将无法正确显示横向,即使只允许纵向。这是iOS 8特有的问题。
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.Portrait.rawValue
}发布于 2015-01-26 07:38:52
在ViewController中:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}Swift版本:
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}发布于 2015-01-27 00:28:51
对于我实现AppDelegate函数应用程序来说,supportedInterfaceOrientationsForWindow做到了
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
if let viewController = self.window?.rootViewController?.presentedViewController as? PortraitViewController{
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}else{
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}其中PortraitViewController应替换为您的根视图控制器类的名称
https://stackoverflow.com/questions/28142530
复制相似问题