changing the digital world one bit at a time...

Blants (noun) the rants of a blogger

  1. XIB iPad orientation in landscape problem and solution

    January 26, 2011 by The Man

    If you want to show a secondary nib file you may have noticed that it shows fine in portrait mode but from startup not in landscape mode.

    This is what I use to fix this. Seems like a fudge but it works, I call this after creating the view.

    vSettings is a UIView and backGroundSettings is a UIImageView.

    - (void) animateFlipInView:(NSString *)theNib;
        UIInterfaceOrientation toInterfaceOrientation = self.interfaceOrientation;
        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:theNib owner:self options:nil];
        vSettings = [nibObjects objectAtIndex:0];
        [self.view addSubview:vSettings];
        if (iPadCheck)
            if ((toInterfaceOrientation == UIDeviceOrientationLandscapeLeft) || 
    			(toInterfaceOrientation == UIDeviceOrientationLandscapeRight)) 
                CGRect contentRect = CGRectMake(0,0,1024,768);
                vSettings.bounds = contentRect;
                CGRect myFrame = vSettings.frame;
                myFrame.origin.x = 0.0;
                myFrame.origin.y = 0.0;
                vSettings.frame = myFrame;
                UIImage *image;
    			image = [UIImage imageNamed: @"Default-Landscape.png"];
                [backGroundSettings setImage:image];
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
        [UIView commitAnimations];