0
votes

I recently had some success using sub views for rotating from portrait to landscape in Xcode 4.5 (iOS 6). Now that the rotation is working, and I can design separate views for portrait and landscape I have run into another problem.

When the app opens in portrait, everything is fine. But when I push a button to navigate to a new screen. the landscape view is showing over top of the portrait view. If I rotate the simulator to landscape then back to portrait, it loads the portrait view.

Everything works as it should in landscape view. This only happens in Portrait view.

in my .h file I have this:

@interface ViewController : UIViewController{


    IBOutlet UIView *portraitView;

    IBOutlet UIView *landscapeView;
}

//rotate views

@property (nonatomic, retain) IBOutlet UIView *portraitView;
@property (nonatomic, retain) IBOutlet UIView *landscapeView;

and in my .m file i have this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    [self.view addSubview:portraitView];
    [self.view addSubview:landscapeView];


}


-(void)didRotate:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIDeviceOrientationPortrait)
    {
        portraitView.hidden = NO;
        landscapeView.hidden = YES;
    }
    else if (orientation == UIDeviceOrientationLandscapeLeft)
    {
        portraitView.hidden = YES;
        landscapeView.hidden = NO;
    }
    else if(orientation == UIDeviceOrientationLandscapeRight)
    {
        portraitView.hidden = YES;
        landscapeView.hidden = NO;
    }

}

I also have one xib file with three views, a main/blank view that contains all the code and a portrait and landscape view connected to the appropriate outlets.

Probably something simple!

Thanks.

1
To clarify, since I am not getting any replies, how do I keep the device from showing landscape view when changing screens in portrait mode?user1510450
Hmmm... Ok to clarify even further: I am navigating between 2 separate xib pages with buttons i.e.... page 1, home. Each page has an xib file with 2 separate views described above. Everything works ok with rotation and changing pages in landscape view. But when I change pages in portrait view, BOTH landscape and portrait views are displaying so that landscape view is over top of portrait view and you can see part of the portrait view in the background. Basically, landscape view is not hidden when changing pages in portrait view. Any suggestions???user1510450
Did you find out the solution?Nam Vu

1 Answers

0
votes

Make sure the view you don't want is hidden. Your code worked perfectly for me. I start with both views hidden, then determine orientation and show that view. For rotation I used the rest of your code..