Search code examples
iosorientationecslidingviewcontroller

bad orientation in screen with multiple viewcontrollers/ views in iOS 7, landscape only (iOS 8 is fine)


I'm using TheSidebarController to implement add a sliding menu into an iOS application. This is the library I'm using, but I've found the same issue in other libraries, like ECSlidingViewController, etc. They essentially work by adding multiple view controllers onto a containing view controller, nothing too crazy.

The issue is, when you make the app a landscape app, all the screens in the container- the menu, the content screen- seem to think they're in portrait mode, and get cut off half way. You can see the issue in this screenshot where the table is cut off: http://imgur.com/xD5MUei

I've been trying to get this to work in any way I can, and no luck.
The library I'm using + example project can be found here: https://github.com/jondanao/TheSidebarController

Any help is greatly appreciated :)

EDIT: people are saying I can stretch the table out to make it look normal, but this just masks the underlying problem, which is the app and/or the screens still think they're in portrait orientation. As a quick example, if I take the example project, and in LeftViewController substitute the following code:

- (void)dismissThisViewController
{
  UIViewController* vc = [[UIViewController alloc] init];
  UINavigationController* pulldown = [[UINavigationController alloc] initWithRootViewController:vc];

  pulldown.view.frame = CGRectMake(pulldown.view.frame.origin.x, -[[UIApplication sharedApplication] delegate].window.frame.size.height,
                                   pulldown.view.frame.size.width, pulldown.view.frame.size.height);
  [[[UIApplication sharedApplication] delegate].window addSubview:pulldown.view];

  [UIView animateWithDuration:.5 animations:^{
    pulldown.view.frame = CGRectMake(pulldown.view.frame.origin.x, 0,
                                     pulldown.view.frame.size.width, pulldown.view.frame.size.height);
  } completion:^(BOOL finished) {
    ;
  }];
}

The viewcontroller comes in sideways, not from the top.


Solution

  • This was a strange one... I had to set the frame of the content view controller, which made sense, but then I had to reset it every time the content was refreshed:

    - (void)setContentViewController:(UIViewController *)contentViewController
    {
        // Old View Controller
        UIViewController *oldViewController = self.contentViewController;
        [oldViewController willMoveToParentViewController:nil];
        [oldViewController.view removeFromSuperview];
        [oldViewController removeFromParentViewController];
    
        // New View Controller
        UIViewController *newViewController = contentViewController;
        [self.contentContainerViewController addChildViewController:newViewController];
        [self.contentContainerViewController.view addSubview:newViewController.view];
        [newViewController didMoveToParentViewController:self.contentContainerViewController];
    
        _contentViewController = newViewController;
        if ([DeviceDetection isDeviceiPad]) {
          _contentViewController.view.frame = CGRectMake(0, 0, 1024, 768);
        }
    }