简体   繁体   中英

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

Use the following in appdelegate.

[self.window addsubview:viewcontroller];

This alone will solve your orientation problem.

With iOS 6, you need to implement the following:

- (BOOL)shouldAutoRotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

In your AppDelegate, you need to change the following:

[self.window addSubview:viewController.view];

to

[self.window setRootViewController:viewController];

Also, keep your current code if you want to support previous versions of iOS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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