restricting autorotation on certain views

Discussion in 'iOS Programming' started by hassoon, Mar 22, 2013.

  1. hassoon macrumors regular

    Joined:
    Jun 8, 2009
    #1
    hi, in my app i toggled the portrait, landscape left/right buttons in the project summary. my app contains a view controller as a root view controller, and a table view controller which the user can navigate to when clicking a button in the view controller. i want to let the user to be able to rotate the screen in the table view but not in the view controller. how can i restrict rotation to a view controller?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  3. hassoon, Mar 22, 2013
    Last edited: Mar 22, 2013

    hassoon thread starter macrumors regular

    Joined:
    Jun 8, 2009
    #3
    HI, i read the ios 6 part since shouldAutorotateToInterfaceOrientation: has been deprecated from ios 6 and onwards. however i didn't find an answer to my problem. i toggled the portrait and landscape left from the project summary and in the view controller (root controller) i added the following:
    Code:
    - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    when running the app, it opens in portrait but when i rotate the device, the view rotates to landscape left. thus the restriction to one orientation from the ones supported failed. i tried using ShouldAutorotate to restrict it to one orientation but it seems it's not even entering the method (i used nslog to detect that).any hint? i want it to open only in portrait no matter how i rotate the device.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Didn't this code give you a warning?

    Anyways, what does your supportedInterfaceOrientations look like?
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    I assume you have a navigation controller. Unfortunately the stock navigation controller doesn't forward calls to the new orientation methods to its topViewController. You need to subclass UNavigationController to return the values from the topViewController.
     

Share This Page