0

我有一个包含图像和表格视图的视图控制器。从这个视图控制器中,我将一个 segue 连接到一个包含全屏图像的横向视图(当您从 Apple 向侧面转动股票应用程序以全屏查看图形时使用的想法相同)。

通过以下方法调用此 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 处于纵向时,我还可以将 tableview 向下钻取几个级别。问题如下:在这些后续级别上,当我将方向转向横向时,仍然会触发横向视图的转接!...我该怎么做才能避免这种情况发生?我只对从包含图像的第一个视图进入横向模式感兴趣。

先感谢您!

4

1 回答 1

1

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

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

应用委托:

在.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;
}

Portrait View Controller(这也是您拥有的非常相似的 segue 处理):

在视图中会出现:

[(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 中都能正常工作。

于 2013-02-01T16:54:07.930 回答