在不受欢迎的视图触发交替景观

我有一个包含图像和tableview的视图控制器。 从这个视图控制器我将一个segue连接到一个包含全屏图像的横向视图(当你从Apple横向转动Stocks应用程序以全屏查看图形时使用相同的想法)。

通过以下方法调用此segue:

- (void)updateLandscapeView { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self performSegueWithIdentifier: @"toGraph" sender: self]; isShowingLandscapeView = YES; } else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView) { [self dismissViewControllerAnimated:YES completion:nil]; isShowingLandscapeView = NO; } } 

除此之外,当iphone处于纵向方向时,我还可以将桌面视图向下钻取更多级别。 问题如下:在那些相应的级别中,当我将方向转换为横向时,仍然会触发到横向视图的segue!…我该怎么做才能发生这种情况? 我只对从第一个包含图像的视图进入横向模式感兴趣。

先谢谢你!

我不确定我的问题是否正确..但如果您的意思是“向下钻取表格视图”以深入了解导航控制器层次结构,您可以尝试以下方法。

这就是我在(我认为)类似情况下所做的事情:

AppDelegate中:

在.h:

 @property (nonatomic) BOOL shouldAutorotate; 

在.m:

//在didFinishLaunchingWithOptions中:

 self.shouldAutorotate = NO; 

//仍然在.m文件中

 // Autorotation handling - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return self.shouldAutorotate ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskPortrait; } 

导航控制器呈现纵向控制器

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (NSUInteger)supportedInterfaceOrientations { if (self.selectedViewController) return [self.selectedViewController supportedInterfaceOrientations]; return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return YES; } 

纵向视图控制器(这里也是一个非常类似的segue处理):

在viewWillAppear中:

 [(AppDelegate *)[[UIApplication sharedApplication] delegate] setShouldAutorotate:YES]; 

旋转处理:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

横向视图控制器(可能是您的全屏图像):

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

更深入的导航控制器层次结构(只需要肖像):

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

看起来有点复杂,但这是唯一的方法,我设法让这些旋转的东西在iOS5和6中正常工作。