How to allow some rotations + not others?

Discussion in 'iOS Development' started by cocotutch, Apr 9, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Hi there,

    Pretty straight forward question:

    "How can I allow certain iPhone Rotations and stop others?"

    I want to stop it from rotating Upside Down and Landscape Right.

    I'm stumped, although my Cocoa knowledge has improved tenfold

    Please Register or Log in to view images



    Thanks.
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    If you're using UIViewControllers (or any subclass of it):
    Code:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
    }
    
    Delete the ones you don't like.
    So in your example:
    Code:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
    }
    
  3. Bubalooshi

    Bubalooshi Active Member

    Joined:
    May 22, 2008
    Messages:
    2,432
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Woah, why's the screen stretched this much?

    Anyways, is it possible to modify any application with this via a jailbreak?
  4. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    The code thing here on the forums doesn't add scrollbars...

    It is, if you get the source code of the app you want to modify or if you write a hook for MobileSubstrate.
    I think there's already a hook for this thing on cydia, but I don't know where.
  5. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    TY!! This really helped. I shouldn't really be coding on Good Friday, but w/evs

    Please Register or Log in to view images

    I don't eat meat though

    Please Register or Log in to view images



    CT

Share This Page