views:

148

answers:

2

I am pretty sure what I am seeing is how this is supposed to work, but I as just curious as to why. When I rotate the iPhone in the simulator the method (see below) that allows the orientation gets called twice with each single rotation. Is there a reason for this?

-(BOOL)shouldAutorotateToInterfaceOrientation:interfaceOrientation

EDIT_001

This is what gets called when the iPhone detects a rotation, I am just curious that each time I do a rotate in the simulator the NSLog statements print twice (i.e. the method is getting called twice)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    BOOL autoRotate = NO;

    switch(interfaceOrientation) {
        case UIInterfaceOrientationPortrait:
            NSLog(@"Orientation(%d): Portrait Supported", interfaceOrientation);
            autoRotate = YES;
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            NSLog(@"Orientation(%d): UpsideDown unsupported", interfaceOrientation);
            autoRotate = NO;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            NSLog(@"Device: RIGHT, Interface: LEFT(%d)", interfaceOrientation);
            autoRotate = YES;
            break;
        case UIInterfaceOrientationLandscapeRight:
            NSLog(@"Device: LEFT, Interface: RIGHT(%d)", interfaceOrientation);
            autoRotate = YES;
            break;
    }
    return(autoRotate);
}

gary

A: 

This happens when the view is inside a tab controller, because the tab controller also calls that same method. Hope that helps.

-Oscar

OscarMk
Silly question, can you explain what the tab controller is or where to find it? Sorry just learning, so no that familiar with all the terminology yet.
fuzzygoat
Sure a tab controller is basically a view controller that lets you switch between views. Documentation here: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarController_Class/Reference/Reference.htmlAlthough If you don't know what a tab controller is, you probably don't have your view inside one. Meaning the problem is something else. Could you post some of your code?
OscarMk
Sure, the code it a bit over-wordy as I am just making things super clear for future reference.
fuzzygoat
Well there is nothing wrong with the code inside that callback. However I would like to see the code where the view controller is instantiated, are you adding it to anything after that?
OscarMk
Almost all the other code is boilerplate from the Xcode template.
fuzzygoat
+1  A: 

Have you checked the arguments passed in to shouldAutorotateToInterfaceOrientation:? I have found it gets called one for horizontal, and once for vertical - basically to ask which orientations are OK, and then it's usually not called again.

If you are doing something in there you want done every time the device is rotated, I think it's a lot better to either use willRotateToInterfaceOrientation:duration: or listen for the rotation notifications (via UIDeviceOrientationDidChangeNotification), and leave shouldAutorotateToInterfaceOrientation: to flag what your app allows for rotation of that view controller.

Kendall Helmstetter Gelner
Thank you, that might just be it. No I don't have any code I want to run there, I was just putting an NSLog in there to verify what was happening.
fuzzygoat