0

Is there an alternative for [[UIApplication sharedApplication] setStatusBarOrientation:animated:]? setStatusBarOrientation, as you can see in it's name, only rotates the status bar. Is there anything that will rotate the whole app like it does when physically rotating the device?

Bo A
  • 3,144
  • 2
  • 33
  • 49

3 Answers3

0

If you want to change the orientation manually (not using autorotation), you will have to rotate and position views yourself, as described in answers to this question. Supporting autorotation is described in the documentation.

Community
  • 1
  • 1
jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • So is there no other way rather than using `setStatusBarOrientation` and `transform`? – Bo A Aug 11 '11 at 18:35
0
if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
    if (!window) {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    }
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    window.transform = CGAffineTransformMakeRotation(-M_PI);
    [UIView commitAnimations];
}

Note: you need the coregraphics framework, I guess.

  • Please add a bit of explanation to your answer for what the code does and how it solves the question. – Ren Nov 11 '12 at 00:33
-2

You can indeed force a rotation this way:

if ([[UIDevice currentDevice] respondsToSelector: @selector(setOrientation:)]) {
  [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationPortrait];
}

Change UIInterfaceOrientationPortrait to UIInterfaceOrientationLandscape if you wish to rotate to landscape

strange
  • 9,654
  • 6
  • 33
  • 47
  • Using something like `NSInvocation` would probably be better so there isn't compilation errors. – Bo A Jan 12 '13 at 19:44