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?

aqua
  • 3,269
  • 28
  • 41
Chris Truman
  • 913
  • 1
  • 7
  • 25
  • 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? – rgeorge Jan 21 '11 at 05:01
  • It is from a UITabBarController Subclass – Chris Truman Jan 21 '11 at 23:38
  • I want only the SLImageViewControllers to rotate when they are visible. All others should stay portrait. – Chris Truman Jan 21 '11 at 23:38
  • 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. – DZenBot Mar 12 '12 at 20:27

1 Answers1

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
Dunja Lalic
  • 752
  • 13
  • 26