Detecting InterfaceOrientation on app start

Discussion in 'iOS Programming' started by sujithkrishnan, May 25, 2010.

  1. sujithkrishnan macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    Hi,

    I am trying to detect the interface orientation in my only viewcontrollers' loadView method. I tried with device orientation, status bar orientation and view controller orientation, where all gives the default (portrait) values.

    I want to show image-A if the startup-orientation is L/S and image-B if portrait.

    Please help!
     
  2. MacToddB macrumors 6502a

    MacToddB

    Joined:
    Aug 21, 2007
    Location:
    Rochester, NY
    #2
    You should ask in the Programming forum. Regardless, have you looked into the Default-Portrait and Default-Landscape files?

    http://developer.apple.com/iphone/library/qa/qa2010/qa1588.html

    Also,

    In your Info.plist file:

    Specify values for the UISupportedInterfaceOrientations key for the supported orientations.
    Specify values for the UIInterfaceOrientation key for the initial launch orientation.
     
  3. sujithkrishnan thread starter macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #3

    I know about the Default-<parameter>.png images. And the device is picking the image based on orientation. I want t get the orientation in my loadView method, where i want to show another image after Default image, but the new image is different for different orientation, All the orientation methods are giving me Portrait/Unknown as return value. :(
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    The orientation will always be portrait when loadView is called. That's fine. Just load up your portrait appearance. Then properly adjust your appearance for rotation.
     
  5. matoch macrumors member

    Joined:
    Oct 12, 2006
    #5
    I was looking at this a bit this morning. From what I can tell by default it seems to load portrait first and then rotate the view. There may be a better way of doing this but this is what I figure should work.

    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
    	portraitBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back-portrait.png"]];
    	landscapeBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back.png"]];
    	self.view.backgroundColor = portraitBackground;
    }

    Code:
    - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    	self.view.backgroundColor = nil;
    	if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
    		self.view.backgroundColor = portraitBackground;
    	}
    	else {
    		self.view.backgroundColor = landscapeBackground;
    	}
    }
     
  6. sujithkrishnan thread starter macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #6


    Sounds good, i wil try .

    Thanks a million
     

Share This Page