iPhone/iPad App Orientation

后端 未结 4 1271
天命终不由人
天命终不由人 2021-01-22 10:24

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

相关标签:
4条回答
  • 2021-01-22 10:40

    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.

    0 讨论(0)
  • 2021-01-22 10:40

    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

    0 讨论(0)
  • 2021-01-22 10:53
    -(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.

    0 讨论(0)
  • 2021-01-22 11:02

    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;
    }
    
    0 讨论(0)
提交回复
热议问题