Reputation:
I would like to create a separate view for when I rotate my app from portrait to landscape in iOS 6. The only significant documentation I can find is on Apple Developer site, but it is not very thorough.
I need a thorough run through of how to set up (and hook up) a portrait view controller and a landscape view controller for rotation purposes.
I managed to get it working using some deprecated iOS 5 methods, but it's not fool proof or fail safe and currently over 80% of iOS users are using iOS 6.
Thanks
Upvotes: 1
Views: 713
Reputation: 5181
Following pmk suggestion, I will extend and suggest you to do the following:
In your xib file, create two different views, besides the UIViewController's view. One of them should be in portrait mode, and the other in landscape.
Declare two IBOutlet views in your interface file, and connect them to the views I explained above:
IBOutlet UIView *portraitView;
IBOutlet UIView *landscapeView;
Now, in your implementation file, you need to be 'aware' of the changes in orientation, and you set the correct one depending on the orientation. In your viewDidLoad you can put:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
And then, finally, you implement something like this:
-(void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscape)
{
portraitView.hidden = YES;
landscapeView.hidden = NO;
}
else if (orientation == UIDeviceOrientationPortrait)
{
portraitView.hidden = NO;
landscapeView.hidden = YES;
}
}
Upvotes: 4