Making one specific class of view controller auto rotate in a tab bar app, but forcing all other classes of view controller to stay portrait
Asked Answered
I

1

3

I have a tab bar controller with this code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //NSLog(@"object type %@"  ,nil);
    if([[self navigationController ] isKindOfClass:[UINavigationController class]])
        if([[[self navigationController] visibleViewController] isKindOfClass:[SLImageViewController class]])
            return YES;
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

I need any instance of the SLImageViewController class to rotate, but none of the others. I have done everything i can think of like adding return YES to my SLImageViewController and other fixes.

Can anyone tell me what I'm doing wrong?

Inexact answered 21/1, 2011 at 4:5 Comment(4)
Is the code above from a UITabBarController subclass, or the UIViewController in one of the tabs? Also.. is this a right understanding of your question: you want autorotation to happen when a specific one of your tabs is showing, but not when one of the others is?Icecap
It is from a UITabBarController SubclassInexact
I want only the SLImageViewControllers to rotate when they are visible. All others should stay portrait.Inexact
This worked for me! Thank you so much! I didn't need to subclass UiTabBarController. I just put that code on the controller I wanted to have auto-rotation.Maieutic
C
3

You could accomplish this by:

  1. setting statusBar orientation to viewWillAppear and viewWillDisappear

-(void) viewWillAppear:(BOOL)animated { [super viewWillAppear: animated]; [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight]; }

-(void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear: animated]; [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait]; }

and rotating a view manually: self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

  1. presenting that view modaly will trigger shouldAutorotateToInterfaceOrientation method
Coreen answered 12/3, 2011 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.