Automatically Sizing UIView after Adding to Window

Posted by Kristopher Johnson on Stack Overflow See other posts from Stack Overflow or by Kristopher Johnson
Published on 2010-04-17T17:53:10Z Indexed on 2010/04/17 18:13 UTC
Read the original article Hit count: 486

Filed under:
|
|
|

I have an iPad app that switches between different views in its main window. The view-switching code looks like this:

- (void)switchToViewController:(UIViewController*)viewController {
    if (currentViewController != viewController) {
        [currentViewController.view removeFromSuperview];
        currentViewController = viewController;
        [window addSubview:viewController.view];
    }
}

The problem is that when the new view (a UISplitView) appears in landscape orientation, it is not sized to fill the entire window. There is an empty black space on the right.

If I rotate the device and then rotate back, the view sizes itself properly. If the device is in portrait orientation, everything works fine. The UISplitView also gets sized properly if it is the first view I show. The problem only occurs if I switch to it after another view has been shown, in landscape.

So, is there some way to force iPhone OS to resize the view after it has been added to the window?

I've tried calling sizeToFit, but it didn't work. I've also tried setting the view's bounds to the window's bounds, and I've tried setting the frame.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ipad