iOS 6 supportedInterfaceOrientations issue

后端 未结 5 1058
傲寒
傲寒 2021-01-17 06:10

In my view controller, I implement two methods for controlling interface orientation:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOr         


        
相关标签:
5条回答
  • 2021-01-17 06:30

    I know this sounds pretty elementary, but I was wracking my brain to figure out orientation issues while testing on my iPhone - I had the physical auto lock mode in Portrait mode - so nothing I changed programmatically mattered - thought this should be troubleshooting step number 1!

    0 讨论(0)
  • 2021-01-17 06:40
    - (BOOL) shouldAutorotate {
        return YES;
    }
    
    // for landscape
    - (NSInteger) supportedInterfaceOrientations {
        return (1 << UIInterfaceOrientationLandscapeLeft) | 
               (1 << UIInterfaceOrientationLandscapeRight);
    }
    

    As noted above, check out the mask values for specific orientations : UIInterfaceOrientationMask values.UIInterfaceOrientationMask

    0 讨论(0)
  • 2021-01-17 06:42

    Two points:

    1. Your error message makes complete sense because it makes no sense to use UIInterfaceOrientationPortrait as a return value from supportedInterfaceOrientations, which is returning a bit mask. Use one of the UIInterfaceOrientationMask values.

    2. You seem to be concerned that if you use the proper UIInterfaceOrientationMaskPortrait, that iOS doesn't appear to call shouldAutorotate. It may only call shouldAutorotate if, having considered the physical device's physical orientation and the app's current orientation against the supportedInterfaceOrientations that a rotation might be needed. Why should it check shouldAutorotate if it concludes that the device is in an acceptable orientation already?

    See supportedInterfaceOrientations and Handling View Rotations for more information.

    0 讨论(0)
  • 2021-01-17 06:47

    In order to change the orientation setting, select menu Targets->Summary-> Supported Device Orientations and change as following.

    If the buttons for the orientation are dark then that means you have selected it as one of the orientation. enter image description here

    0 讨论(0)
  • 2021-01-17 06:50

    rather than using an integer to declare the orientation why don't you use a bool and plug in a if statement in there to detect whatever orientation you want. here is a example code that i hope would help you:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return YES;
    }
    if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        return YES;
    }
    return NO;
    }
    

    you can add all of the orientations in the if statement and it should work just fine. adrian

    Edit:

    and if you want to have an option for ios 6 the below code should work just fine for you.

    - (BOOL) shouldAutorotate
    {
    return YES;
     }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft   | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    

    you can change just about all the supported orientations with this in ios 6. happy coding

    EDIT 1:

    to rotate only certain viewcontrollers in a certain way, just use the ios 6 code that i posted above in all viewcontrollers. here are the steps:

    1. in the project level where all four internfaceorientations are located, go ahean and turn everything off so app would go to default.

    2. implement the ios 6 code that i supplied in all viewcontrollers.

    3. rather than yes declare no in shouldautorotate method.
    4. in the second method, plug in any type of orientation you want.

    this should do the trick for you. happy coding

    0 讨论(0)
提交回复
热议问题