Pergunta

I have an app where landscape left and landscape right are both enabled in the build settings, but I'd only like these to be available in one ViewController in the app.

I'm using a navigation controller, and in the first ViewController I push onto the stack, I'd like to disable rotation altogether. I've tried all 3 of these with no success:

- (BOOL)shouldAutoRotate {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

When I rotate the device in the simulator, the layout still changes. I know the last method is deprecated in iOS 6.

Any ideas?

Foi útil?

Solução

Fixed it. The reason was because the navigation controller was being rotated, and this was not triggering - (BOOL)shouldAutorotate to be called in the top view controller, as I thought it would.

I subclassed the navigation controller and added

- (BOOL)shouldAutorotate {
    return NO;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top