Auto-rotating freshly created interface

Posted by zoul on Stack Overflow See other posts from Stack Overflow or by zoul
Published on 2010-05-06T14:01:06Z Indexed on 2010/05/06 14:48 UTC
Read the original article Hit count: 294

Filed under:
|
|

Hello! I have trouble with auto-rotating interfaces in my iPad app. I have a class called Switcher that observes the interface rotation notifications and when it receives one, it switches the view in window, a bit like this:

- (void) orientationChanged: (NSNotification*) notice
{   
    UIDeviceOrientation newIO = [[UIDevice currentDevice] orientation];
    UIViewController *newCtrl = /* something based on newIO */; 
    [currentController.view removeFromSuperview]; // remove the old view
    [window addSubview newCtrl.view];
    [self setCurrentController:newCtrl];
}

The problem is that the new view does not auto-rotate. My auto-rotation callback in the controller class looks like this:

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) io
{   
    NSString *modes[] = {@"unknown", @"portrait", @"portrait down",
        @"landscape left", @"landscape right"};
    NSLog(@"shouldAutorotateToInterfaceOrientation: %i (%@)", io, modes[io]);
    return YES;
}

But no matter how I rotate the device, I find the following in the log:

shouldAutorotateToInterfaceOrientation: 1 (portrait)
shouldAutorotateToInterfaceOrientation: 1 (portrait)

…and the willRotateToInterfaceOrientation:duration: does not get called at all. Now what? The orientation changing is becoming my least favourite part of the iPhone SDK… (I can’t check the code on the device yet, could it be a bug in the simulator?)


PS. The subscription code looks like this:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(orientationChanged:)
    name:UIDeviceOrientationDidChangeNotification
    object:nil];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ipad