views:

602

answers:

0

Hello together

I'm trying to add rotation support to our application which we are currently developing. Unfortunately its not working. So I created a small test project to test what the reason could be. And I found a strange behavior which I cannot explain.

In my test project I have two RotationTestViewController (extended from UINavigationControllers) instances. The first UINavigationController will be displayed on application start and it shows an label and a button in the view. When we click on this button the following code will get executed:

- (void) doIt {
 RotationTestViewController *navCon = [[[RotationTestViewController alloc] init] autorelease];

 UIViewController *uvc = [[[UIViewController alloc] init] autorelease];
 UIBarButtonItem *retryButton =  [[[UIBarButtonItem alloc] initWithTitle:@"Back to view 1" style:UIBarButtonItemStyleDone target:self action:@selector(doItBack)] autorelease];
 uvc.navigationItem.rightBarButtonItem = retryButton;
 uvc.title = @"View 2";

 CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
 CGRect r = CGRectMake(0, 0, webFrame.size.width, webFrame.size.height);
 UILabel *label = [[[UILabel alloc] initWithFrame:r] autorelease];
 label.text = @"View 2 Test";

 uvc.view.autoresizesSubviews = YES;
 label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

 [uvc.view addSubview:label];

 [navCon pushViewController:uvc animated:NO];

 self.viewController2 = navCon;

 // Override point for customization after app launch    
 [window addSubview:navCon.view]; // LINE A
 [[[window subviews] objectAtIndex:0] removeFromSuperview];
 //[window addSubview:navCon.view]; // LINE B
}

RotationTestViewController is my custom subclass of the UINavigationController and enables the rotation of the controller (It returns YES). The interesting thing is now that this view 2 which will shown by this code will not rotate.

But when I comment LINE A out and comment LINE B in the view is able to rotate as it should. My problem is that I don't understand the reason for this behavior.

I have tested this with the Simulator (for the version 2.2/2.2.1 and 3.0) and on the device (for the version 2.2 and 2.2.1)

Here you can download my simple test project: http://vmac.ch/RotationTest.zip

I hope someone has an idea what the reason for this could be.

Thanks and greetings Chris