iOS 6 supportedInterfaceOrientations issue

后端 未结 5 1103
傲寒
傲寒 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: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

提交回复
热议问题