-1

I'm developing a universal app. When my device is ipad I have 2 designs: Portrait and landscape.

I use this method: -(void)orientationDidChanged:(NSNotification *)notification

It works perfectly when I rotated my device. But I have a problem, when first load the view and I have not rotated the device. For that reason, I put this code in the viewdidload:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ //
     something.
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    NSLog(@"IPAD ** ");
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
        NSLog(@" vertical ** ");
    }
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
         NSLog(@"Horizontal ** ");
    }
}

My problems is this: sometimes it works , sometimes not :(. This method: orientationDidChanged, when start to work? only if I rotate my device or immediately with the viewDidLoad , is necessary ask one more time the orientation when I have that method? Thanks for some advice.

I don't have problem when I rotated my device, it works perfectly :D .. My problem is when I recently run the application and I haven't turned the device

user2958588
  • 13
  • 1
  • 6
  • I want to know why mark my question like negative, I would appreciate if you let me know. I'm learning english and I think that my question is clear, I don't have problem when I rotated my device, somebody tell me what I did wrong! – user2958588 Jul 14 '14 at 23:37
  • I have to write well my question, but you need to read well my problem, somebody delete your answer, :( I don't understand how works it! – user2958588 Jul 14 '14 at 23:39
  • I solved with this: http://stackoverflow.com/questions/3382937/how-do-i-detect-an-ipads-interfacerotation-at-the-start – user2958588 Jul 15 '14 at 15:57

1 Answers1

0

You can use this:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(orientation == 0) //Default orientation 
    //UI is in Default orientation (Portrait)
else if(orientation == UIInterfaceOrientationPortrait)
    //UI is in Portrait orientation
else if(orientation == UIInterfaceOrientationLandscapeLeft)
    //UI is in Landscape-left orientation
else if(orientation == UIInterfaceOrientationLandscapeRight)
    //UI is in Landscape-right orientation
Mikel Pascual
  • 2,202
  • 18
  • 27