Question

I need to detect device orientation before running viewDidLoad method in controller. I tried all solutions purposed in other questions but I can't solve.

What's the best way using SotryBoard in xCode 5 and iOS 7 to do that?

Thank you in advance!

EDIT: Actually I'm using

- (void)viewDidLoad {

    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

        switch ([[UIDevice currentDevice] orientation]) {
            case (UIDeviceOrientationPortrait):
                // landscape layout
                break;

            default:
                // portrait layout
                break;
        }

but it does't work...

SOLVED: using

- (void)viewDidLoad {

    [super viewDidLoad];

    if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        // Portrait
    }

    if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
        // Landscape
    }
}
Was it helpful?

Solution 2

Try checking the status bar orientation:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

Also there are a few other view controller methods fired before viewDidLoad. Look at awakeFromNib and initWithCoder.

OTHER TIPS

[[UIDevice currentDevice] orientation] is what you need?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top