Is it possible to run similar in Landscape mode at first?

Discussion in 'iOS Programming' started by mikezang, Sep 29, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I want to my app run in landscape mode at first, I tried to add init in landscape to app plist, but I didn't get what I need, it will be in portrait mode all time, is it possible in landscape mode when simulator started?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Leave your Simulator running in landscape-mode and then Build and Run your app.
     
  3. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #3
    You need a key in your applications main plist

    <key>UIInterfaceOrientation</key>
    <string>UIInterfaceOrientationLandscapeRight</string>


    Then you need to make sure to return to only allow the Right view (in this case) in all your views that load:
    Code:
    - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    
     
  4. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #4
    It is ok, but not what I need, because I have run simulator at first and turn it left, then run my app.
    Thanks, I will use it if I can't find better way.
     
  5. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #5
    Well, When I run it, simulator turned in landscape mode, this is what I need.
    But when I turned it left, I got a screen what I don't need, how can I solve it?
     

    Attached Files:

  6. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #6
    What I linked will load it and "lock" it in landscape right mode. If you want it to automatically roll with the direction you have it facing, you have to return YES for each orientation you want to support:

    Code:
    - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationPotrait));
    }
    
    This would allow your app to run in portrait mode and in landscape-right mode. Of course you then have to do some view transformations in probably the viewDidAppear method otherwise your UI will look goofy as it rotates because none of the UI elements will be in the right place.
     
  7. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #7
    My question might be not so clear, I need run my app on both mode, so I return YES for shouldAutorotateToInterfaceOrientation before I post here.
    My exact question is how to show simulator in landscape mode when start to run my app, then I can turn it left or right in portrait or landscape mode, may I make sense?
     
  8. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #8
    That's what putting that key in your main plist above does. You have to understand, you can't force someone to hold the device a certain way when they start your app. If they are holding it in portrait mode, because you allow both portrait and landscape, it will start up in landscape mode and flip to portrait mode as soon as the view finishes loading.

    I honestly don't see much of a point forcing your app to start in landscape mode if you are going to allow your app to be run in both portrait and landscape mode. When it finishes loading, it's just going to flip to whatever orientation the user is holding it in, and for most of us, that's going to be portrait.
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Yes, makes sense. And the only way I know how to force the Simulator to start with a certain orientation is to already have it running that way when you start your app, as I mentioned above.

    P.S. Quick English lesson, Mike. The proper phrasing would be "does that make sense?"
     
  10. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #10
    Thanks, dejo, I try to improve my English:)

    By the way, I want to know if it is a native English for "May I make sense?", when it can be used if it is?
     
  11. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    That phrase would be rarely used, if ever. You are asking for permission to make sense!
     

Share This Page