2

The iPhone version of my app supports UIDeviceOrientationPortraitUpsideDown and UIDeviceOrientationPortrait, but the iPad version supports all Orientations.

In my view controller I have this:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation     {
    return YES;
}

and my Info.plist file has this:

enter image description here

The problem is that when I build the app to my iPod, the app won't turn upside down. The iPad will support all Orientations.

I've tried removing the shouldAutorotateToInterfaceOrientation all together and I've tried this code:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation = UIDeviceOrientationLandscapeLeft) && (interfaceOrientation = UIDeviceOrientationLandscapeRight) && (interfaceOrientation = UIDeviceOrientationPortraitUpsideDown) && (interfaceOrientation = UIDeviceOrientationPortrait);
}

But for some reason, the upside down just won't work! Are there any other solutions for this?

Edit: using Xcode 4.5 iOS6

tcd
  • 1,585
  • 2
  • 17
  • 38

4 Answers4

3

Figured it out, the iOS6 SDK uses shouldAutorotate so here is my new code:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

-(BOOL)shouldAutorotate {
     return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
tcd
  • 1,585
  • 2
  • 17
  • 38
  • So do you have to have both -(BOOL)shouldAutorotate? or do you just need the one for IOS6 SDK? – Zack Sep 22 '12 at 03:16
  • I used both because iOS – tcd Sep 22 '12 at 03:18
  • 1
    Okay cool. Keep me updated on that please cause it would be interesting to see whether you will just have to keep the one or have to keep both – Zack Sep 22 '12 at 03:19
  • as for the difference on iPhone and iPad, I defined those in my info.plist – tcd Sep 22 '12 at 03:19
  • Hello All. I tried to use this also but it is not working for me. Please help me for this. I am stuck now. Thanks. – Mohd Haider Apr 06 '14 at 16:00
0

If I understand you correctly, you want the iPad to support all orientations while you want the iPhone to support just rotation of upside down and portrait. Try this as a solution. (this is a simpler way then what you are doing above)

   -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
          return YES;
     }

    else {
            return UIInterfaceOrientationIsPortrait(interfaceOrientation);
        }
 }

I would also like to add that you MUST ADD THIS INTO EACH SEPARATE VIEW CONTROLLER in order for it to rotate for the other view as well.

For instance, lets say I have viewcontroller_1 and viewcontroller_2, I have to go into both .m files of the controller and add the following code. If you dont, it may not rotate for one of the views.

Zack
  • 871
  • 10
  • 24
  • Thanks for your response, I resolved it with the code I posted in my own answer, check it out. – tcd Sep 22 '12 at 03:15
0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

This method is deprecated in IOS 6 so instead of it you can use below method.

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

return orientation according to you.

TheTiger
  • 13,264
  • 3
  • 57
  • 82
0

Another way to support orientations is to subclass UINavigationController and add your orientation code there

i.e

//IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}
//IOS 6
- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

this worked for me, using storyboards

Tony
  • 656
  • 8
  • 20