简体   繁体   English

iPhone界面方向更改未恢复为纵向

[英]iPhone interface orientation change not returning to portrait orientation

So I have a view that I present modally when the interface orientation changes to landscape. 因此,我有一种看法,即在界面方向变为横向时以模态形式呈现。 However when the orientation returns to portrait and the modal view dismisses itself, the tableview from the initial view remains in landscape orientation (this table view must be only in portrait orientation) 但是,当方向恢复为纵向并且模态视图消失时,初始视图的表视图将保持横向(此表视图必须仅以纵向方向)

Here is the code : 这是代码:

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

I tried to refresh the tableview but that doesn't make it portrait again ... this could be from the view hierachy ... NavigationController->tableView (only portrait)->tableview->landscapeViewModalController 我试图刷新tableview,但是不会再次使其变为纵向...这可能是从视图层次结构中获取的... NavigationController-> tableView(仅纵向)-> tableview-> landscapeViewModalController

Use the following in appdelegate. 在appdelegate中使用以下内容。

[self.window addsubview:viewcontroller];

This alone will solve your orientation problem. 仅此一项就可以解决您的定向问题。

With iOS 6, you need to implement the following: 使用iOS 6,您需要实现以下功能:

- (BOOL)shouldAutoRotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

In your AppDelegate, you need to change the following: 在您的AppDelegate中,您需要更改以下内容:

[self.window addSubview:viewController.view];

to

[self.window setRootViewController:viewController];

Also, keep your current code if you want to support previous versions of iOS. 此外,如果要支持iOS的早期版本,请保留当前代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM