How to get current orientation of device programmatically in iOS 6?

前端 未结 8 746
庸人自扰
庸人自扰 2020-12-30 23:50

I have developed an iOS App and tested it on iOS6 device. While testing, I realized that my App is not responding to Orientation changes as expected.

Here is my Code

相关标签:
8条回答
  • 2020-12-31 00:35

    In your ViewController, you can use didRotateFromInterfaceOrientation: method to detect when the device has been rotated and then do whatever you need in every orientation.

    Example:

    #pragma mark - Rotation
    
    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        switch (orientation) {
            case 1:
            case 2:
                NSLog(@"portrait");
                // your code for portrait...
                break;
    
            case 3:
            case 4:
                NSLog(@"landscape");
                // your code for landscape...
                break;
            default:
                NSLog(@"other");
                // your code for face down or face up...
                break;
        }
    }
    
    0 讨论(0)
  • 2020-12-31 00:41

    You can try this, which solves your problem.

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    

    Refer below link for App extension Get device current orientation (App Extension)

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