我正在构建一个仅适用于主要视图(正常和倒置)的纵向应用程序.我已经在项目设置/Plist 中设置了这个设置,一切正常.但是,我有一些模态视图可以执行显示图像/视频之类的操作,我希望它们能够旋转到所有方向.
I am building an app that will be Portrait only for the main views (Both normal and upside down). I have set this setting in the Project Settings/Plist and all works fine. However, I have a few modal views that do things like display images/videos, and I want them to be able to rotate to ALL orientations.
我尝试为 UINavigationController 添加一个类别,但没有成功.我还向调用模态的 viewController 添加了以下代码:
I tried adding a category for UINavigationController but no luck. I have also added to the viewController that calls the modal the below code:
-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
return NO;
}
-(BOOL)shouldAutomaticallyForwardRotationMethods{
return NO;
}
我已将以下代码添加到我希望允许所有方向的模态视图控制器中:
I have added the below code to the modal viewControllers that I want to allow all orientations:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
我错过了什么?有什么建议吗?
What am I missing? Any suggestions?
在 iOS 6 上,旋转处理发生了变化.对于您描述的问题,有几种方法.首先,在 plist 中,启用除纵向倒置之外的所有方向.
On iOS 6, rotation handling has changed. For the problem you described, there are several approaches. First, in the plist, enable all orientations except portrait upside down.
那么您可以使用以下解决方案之一:
Then you could use one of the following solutions:
您可以覆盖应用程序委托中的方法.由于每当方向更改或推送新的视图控制器时都会在您的委托上调用该方法,您可以使用它来临时启用/禁用应用程序的横向显示:
You can override a method in your application delegate. As that method is called on your delegate whenever the orientation changes or a new view controller is pushed, you can use it to temporarily enable/disable landscape display for your app:
// In AppDelegate.h:
@property (nonatomic) BOOL portraitOnly;
// In AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return _portraitOnly ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskAllButUpsideDown;
}
// to switch to portrait only:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = YES;
// to switch to allowing landscape orientations:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = NO;
这篇关于iOS 6 - 某些视图的导航控制器横向旋转,而其他视图仅纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!