iPhone界面方向更改未返回纵向



因此,当界面方向变为横向时,我有一个以模式呈现的视图。但是,当方向返回到纵向并且模式视图自行消失时,初始视图中的表视图仍处于横向(此表视图必须仅处于纵向)

这是代码:

- (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];
}
}

我试图刷新表视图,但这并不能使其再次成为人像。。。这可能是从等级的角度来看。。。NavigationController->tableView(仅纵向)->tableView->landscapeViewModalController

使用iOS6,您需要实现以下功能:

- (BOOL)shouldAutoRotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

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

[self.window addSubview:viewController.view];

[self.window setRootViewController:viewController];

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

在appdelegate中使用以下内容。

[self.window addsubview:viewcontroller];

仅此一项就可以解决你的定向问题。

最新更新