【问题标题】:iPhone interface orientation change not returning to portrait orientationiPhone界面方向更改未返回纵向
【发布时间】:2012-11-13 16:27:51
【问题描述】:

所以我有一个视图,当界面方向变为横向时,我会以模态方式呈现。但是,当方向返回纵向并且模态视图自行关闭时,初始视图中的表格视图仍保持横向(此表格视图必须仅纵向)

代码如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
        [self performSegueWithIdentifier:@"showCatChart" sender:self];
    }
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
        [self refreshTableView];
    }
}

我尝试刷新 tableview 但这并没有使它再次成为纵向... 这可能是从层次结构来看...... NavigationController->tableView(仅纵向)->tableview->landscapeViewModalController

【问题讨论】:

  • 那是关于 iOs6 的 .. 我需要在 iOs 5/6 iPhone 3gs/4/4s/5 上进行这项工作 ...
  • 没什么好担心的,你也应该在 viewController 中保留 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法。

标签: iphone ios uiinterfaceorientation autorotate


【解决方案1】:

使用 iOS 6,您需要实现以下内容:

- (BOOL)shouldAutoRotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

在您的 AppDelegate 中,您需要更改以下内容:

[self.window addSubview:viewController.view];

[self.window setRootViewController:viewController];

此外,如果您想支持以前版本的 iOS,请保留您当前的代码。

【讨论】:

    【解决方案2】:

    在 appdelegate 中使用以下内容。

    [self.window addsubview:viewcontroller];
    

    仅此一项就可以解决您的方向问题。

    【讨论】:

    • 而viewController应该是什么?最初的导航控制器?
    • 是的,将导航控制器用作 [self.window addsubview:navigationcontroller.view];
    • 不起作用...同样的问题...视图返回纵向模式,但其中的显示看起来像横向...
    猜你喜欢
    • 1970-01-01
    • 2016-05-03
    • 2014-08-15
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 2014-07-15
    • 1970-01-01
    相关资源
    最近更新 更多