7

In One of my Viewcontroller that supports only Portrait orientation. On my device when rotate the status bar is rotating to landscape orientation. The rest of the view remains in Portrait mode. I want to prevent the roation of statusbar. This problem is happening only in IOS7

// Overridden function to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        // iPhone: support only upright portrait
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    else 
    {
           // iPad: any orientation is OK
            return YES;
     }
}

// For iOS6.0 Rotate
- (BOOL)shouldAutorotate
{
    return NO;
}
Sabareesh
  • 3,585
  • 2
  • 24
  • 42
  • 2
    the method `-shouldAutorotateToInterfaceOrientation` is deprecated since iOS 6, you need to use `-supportedInterfaceOrientations` instead – medvedNick Oct 30 '13 at 16:12
  • 1
    Just a heads up - I tried out your code on a clean new single-view project and the status bar doesn't rotate (Simulator, iOS 7). If your view controller class is inherited you might want to check up the chain, or check the supported interface orientation settings in project/target settings in Xcode. – Jai Govindani Oct 30 '13 at 16:44
  • Thanks for the reply, In simulator it is ok, Only in device this problem is happening. – Sabareesh Oct 30 '13 at 16:52
  • 2
    I have the same issue. If I run the app from scratch it doesn't happen, but if I return to the home screen then back into the app again the issue arises. This is quite frustrating as I am absolutely certain I am returning the correct value in `-supportedInterfaceOrientations`. – Trebor Dec 19 '13 at 11:43

1 Answers1

0

Use this method to keep it in Portrait view :

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
itsji10dra
  • 4,603
  • 3
  • 39
  • 59