PDA

View Full Version : Navigation, TabBarController, subviews in landscape




estupefactika
May 27, 2009, 05:11 AM
Hi, I want to change the orientation to landscape in all my app. I have a navigationController and a tabBarController. I did this and it works fine, but I have a little problem with the orientation of the UIWindow.

I detail what I did:

I made a Custom Tab Bar Controller class , over-rode shouldAutorotateToInterfaceOrientation for this class.


//In applicationDidFinishLaunching
tabBarController = [[TabbarController alloc] initWithNibName:nil bundle:nil];
[tabBarController setViewControllers:controllers animated:YES];
tabBarController.customizableViewControllers = controllers;
tabBarController.delegate = self;

tabBarController.moreNavigationController.navigationBar.tintColor=[UIColor blackColor];
[tabBarController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
// Set up the window
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];


In info.plist, I added:
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>


And it works, my navigation, tabBarcontroller and my subviews are in landscape. But in my viewController I have a subview of UIWindow that i dont get to rotate, its a subview that covers the entire screen and I remove it after:

startView= [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f, 480.0f, 320.0f)];
startView.backgroundColor = [UIColor blackColor];

logo =[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 298.0f, 26.0f)];
logo.image=[UIImage imageNamed:@"logo.png"];
logo.contentMode=UIViewContentModeScaleToFill;
[startView addSubview:logo];
logo.center=CGPointMake(250,100);
[logo release];

[window addSubview:startView];


window is in portrait, I tested this:

// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
window.transform = transform;

// Repositions and resizes the view.
CGRect contentRect = CGRectMake(0, 0, 480, 320);

window.bounds = contentRect;


If I do this, window is in landscape but rest of my app is broken graphically.

Am I missing something? Any idea? Thanks