0

I simply want to lock rotation for the status bar when some conditions are fulfilled:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

        if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
          if(imageView.hidden == NO){        

            //lock the status bar rotation
          }else{
            //unlock the status bar rotation
          }
        }
}

Anyway to lock/unlock the status bar programmatically? Thanx.

Malloc
  • 15,434
  • 34
  • 105
  • 192

1 Answers1

0

You need to override the proper methods in your view controller class. In iOS 6+ you need to override supportedInterfaceOrientations. If you also need to support iOS 5 also override shouldAutorotateToInterfaceOrientation:.

Both implementations should return appropriate values on the currently allowed orientations.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • I am showing a modal view (`UIView` subclass), adding it to the window (not the view controller) in order to lock it from rotation. Everything works fine except the status bar which gets rotated when moving to landscape. So I need to lock it WHILE the modal view is shown. That's it :) Is there anyway to do so? I tried to set [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationMaskAll; but it doesn't work – Malloc Sep 12 '13 at 22:54
  • My answer assumed you were using a view controller. I'm not sure what to do in your case. – rmaddy Sep 12 '13 at 22:58
  • Never mind, I found make it hidden to be the best way to go in my case: `[UIApplication sharedApplication].statusBarHidden = YES;` – Malloc Sep 12 '13 at 23:19