开发者

iPhone, duplicate method message after hardware rotate?

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:
开发者_JAVA技巧            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


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.


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

-Oscar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜