How to keep a screen landscape

Discussion in 'iPhone/iPad Programming' started by arnieterm, Feb 17, 2009.

  1. macrumors regular

    Joined:
    Aug 28, 2008
    #1
    Instead of designing [using IB or through code] a screen in landscape mode, how can we make a screen to always look in landscape mode even if the user rotates the iphone.
    My problem is that with a touch on a button I have to show a screen in landscape and that screen needs to remain in landscape even if the iphone is rotated to left or right. There is another button on second screen that when touched by user will again take to first screen and in that case the screen needs to again come in the state in which it is originally.

    With Regards
    Parvez Qureshi
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    The answer lies in the shouldAutorotateToInterfaceOrientation: method of your view controller.
     
  3. macrumors newbie

    Joined:
    Nov 25, 2008
    #3
    first ,you should disable the autoratate ,that means you should Return false in the shouldAutorotateToInterfaceOrientation: method of your view controlle.
    then ,you could use code like
    [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

    [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];

    [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];

    to make your iphone in landscape mode or back to portrait mode.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    That's only going to affect the statusBarOrientation and not anything else in the UI. There's a little more to what the OP wants, I believe.

    arnieterm, I'd suggest you stop by my iPhone Programming Tutorial - Landscape-Only View-Based Application blog posting.
     
  5. macrumors newbie

    Joined:
    Nov 25, 2008
    #5
    That's will also rotate the other UI element of the screen .
    And i think OP's app shouldn't be landscape only :)
     

Share This Page