简体   繁体   中英

Rotating UIViewController Problem

I have the following code to display a UIViewController in horizontal orientation ontop of a UITableViewController.

  -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        [self.view addSubview:landscapeChartViewController.view];
    }

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
        toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        if(landscapeChartViewController != nil)
            [landscapeChartViewController.view removeFromSuperview];
    }
}

When the phone rotates, the view doesn't take up the entire screen.

The user is also able to scroll, thus showing the rest of the UITableViewController. I don't want the UITableViewController to be there in horizontal orientation.

Try [self.view addSubview:landscapeChartViewController.view];

Assuming you've set your frames correctly, this should be what you're looking for.

landscapeChartViewController.view.frame = self.view.bounds , perhaps?

Also keep in mind that the orientation change can happen "in the background" if you're using a tab bar controller, so you might also want to check the current orientation in -viewWillAppear: .

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