我有一个主视图控制器这是一个UINavigationController内。 在主视图控制器,我有一个按钮,按下具有在其内部一个UIWebView的详细视图控制器。 我想,当它的加载这个细节视图控制器是在横向模式。 让我们再回到主视图控制器,它强行再次返回到肖像模式。 我在这头运行iOS 6。
我见过的其他类似的问题,但它不工作在我结束。 我创建了一个LandscapeViewController那的UIViewController的一个子类,我已经写了这些方法:
#pragma mark - Orientation Methods
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate
{
return YES;
}
这是我的代码时,我推详细视图控制器:
DetailViewController *detailVC = [[DetailViewController alloc]
initWithNibName:@"DetailViewController"
bundle:nil];
[self.navigationController pushViewController:detailVC
animated:YES];
我想在哪里继承我的LandscapeViewController在上面的代码,使其工作或如何正确地继承和推动我详细视图控制器。 我也可以介绍我的详细视图控制器模态,如果它是不可能的导航控制器从纵向把我的详细视图控制器的风景线。 我在哪里做错了?
只有景观:视图B - 只有人像:考虑:观
我不能这样做,在导航控制器。 相反,我所做的就是打开从视图中的模态的视图以查看B和强制一个新的导航控制器到这一观点。
这在iOS5中+为我工作。
您需要创建导航控制器这样的分类:
UINavigationController的+ Rotation_IOS6.h
#import <UIKit/UIKit.h>
@interface UINavigationController (Rotation_IOS6)
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end
UINavigationController的+ Rotation_IOS6.h
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
@end
在AppDelegate.m补充:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
然后在视图A:
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
也是在一个视图中打开视图B做到这一点:
ViewB *vc = [[ViewB alloc] initWithNibName:@"ViewB" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:navigationController animated:YES completion:nil];
最后,在视图B
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
他们有点拧狗在iOS 6中关于这一点。 这是我到目前为止已经想通了:
首先,苹果增加了“支持的界面面向”按钮和Xcode 4.5。 这对应于_info.plist“支持的接口方向”属性。 这些按钮必须切换到正确的选择之前的任何其他部分的正常工作。 (如果按钮似乎拒绝切换很可能是因为Info.plist中由CVS或一些其他进程锁定。)
接着,属性.window.rootViewController必须设置,并且必须指向在堆栈中的“底部”视图控制器。 通常,这将是或者是导航控制器或选项卡控制器。
如果愿望是禁用所有的旋转,这可以用按钮来完成,或者一个可以实现,在“底部”视图控制器时,“shouldAutorotate”的方法,并使其返回NO。 (如果省略该方法则缺省为YES)。
尽管具有shouldAutorotate禁用自转的,如果存在正显示MPMoviePlayerViewController,将自转。 只有拨动支持的接口方向按钮似乎防止这一点。
如果一个人想有条件地自转其他视图控制器它变得混乱。 基本上,你的“底”视图控制器必须实现基于当前topViewController,相应的位掩码的supportedInterfaceOrientations方法和回报。 这可以用查询topViewController的老“shouldAutorotateToInterfaceOrientation”方法的例程中完成,但它是一个有点难看。 而且即使该方案不需要修改旋转视图控制器的代码,你需要修改VC只是“下面的”旋转一个实施“supportedInterfaceOrientation”,否则这一观点将在返回旋转。 (至少这是一个简单的复制/粘贴)。似乎没有人想出了一个更好的,更普遍的方案,虽然。