我有这个应用程序,我正在工作,我需要我的所有视图控制器,但一个在肖像。单一的一个视图控制器,是特别的,我需要它能够旋转到任何方向的手机是在。
要做到这一点,我将以模式(而不是嵌入在NavigationController中)的方式呈现它。
所以(例如)我的结构如下:
现在,当我将我的模态视图控制器放在一个景观位置时,我的父视图控制器也会被旋转,即使它不支持这个方向。
应用程序中的所有UIViewControllers和UINavigaionControllers都继承了具有以下方法的相同的通用类:
override func supportedInterfaceOrientations() -> Int
{
return Int(UIInterfaceOrientationMask.Portrait.toRaw())
}我的模态视图控制器再次重写该方法,它看起来如下:
override func supportedInterfaceOrientations() -> Int
{
return Int(UIInterfaceOrientationMask.All.toRaw())
}更新1
看起来这只发生在iOS8 Beta上。有人知道在视图控制器的旋转方面是否有什么变化吗?还是这只是测试版中的一个bug?
发布于 2014-12-19 07:51:36
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([self.window.rootViewController.presentedViewController isKindOfClass: [SecondViewController class]])
{
SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
if (secondController.isPresented)
return UIInterfaceOrientationMaskAll;
else return UIInterfaceOrientationMaskPortrait;
}
else return UIInterfaceOrientationMaskPortrait;
}还有斯威夫特
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
if self.window?.rootViewController?.presentedViewController? is SecondViewController {
let secondController = self.window!.rootViewController.presentedViewController as SecondViewController
if secondController.isPresented {
return Int(UIInterfaceOrientationMask.All.toRaw());
} else {
return Int(UIInterfaceOrientationMask.Portrait.toRaw());
}
} else {
return Int(UIInterfaceOrientationMask.Portrait.toRaw());
}
}有关更多详细信息,请查看此链接
发布于 2014-09-09 13:03:18
我的一个应用程序也有同样的问题,经过几天的实验,我想出了一个不太好的解决方案,但它现在起作用了。我在应用程序委托中使用委托方法application:supportedInterfaceOrientationsForWindow:。
我创建了一个测试项目,并将其放入在github上 (包括显示结果的GIF )。
//注意:它不是很快的,但我希望它能帮上忙
发布于 2014-06-28 23:19:10
经过多次实验,我确信这是iOS 8的一个“特性”。
如果你想一想,这是完全合理的,因为它已经出现了很长时间。
https://stackoverflow.com/questions/24229677
复制相似问题