문제

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