سؤال

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
    }
}
هل كانت مفيدة؟

المحلول 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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top