2

所以我有一个 UITableViewControler 以纵向模式显示一个表格视图。

一旦我旋转 iPhone,我想以横向模式呈现模式视图。

在我使用的 tableView 中:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

并处理当前的模态视图:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
        if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
        {
            NSLog(@"Push page view");
            PagingViewController *s = [[PagingViewController alloc] initWithNibName:@"PagingView" bundle:nil];
            s.hidesBottomBarWhenPushed = YES;

            [self presentModalViewController:s animated:YES];
            [s release];
        }
}

模态视图我有以下内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

为了消除模态视图本身,我这样做:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        NSLog(@"Dismiss my self");
        [self.parentViewController dismissModalViewControllerAnimated:YES];
    }
}

一些这是如何工作的两次。我第三次将 iPhone 从纵向模式旋转到横向模式时,我遇到了错误的访问错误。

我无法弄清楚是什么给了我错误。有人在乎打吗?

4

1 回答 1

0

我能想到的最简单的方法是实现 -shouldAutorotate... 并关闭模式视图并返回 NO 以中止旋转。也许这足以避免任何并发问题。如果您不喜欢这个建议,请查看 NSNotificationCenter。

于 2011-06-14T21:44:52.887 回答