0

I would like to set different rules for the different viewControllers in my apps, not a single rule across all views (like you can define in Target-Summary).

For instance I have several views I would like my first few views to only appear in portrait view, however in my last view I would like the user to be able to change between protrait and landscape... I was woundering how I could do this.

Also I have read issues where the user navigates to a view while in landscape and the view appears landscape when it should be portrait and will not change untill the user rotates the device, I would like to avoid this if possible...

So my question is how can I allow different UIViewController Orientations depending on which view the user is in.

HurkNburkS
  • 5,492
  • 19
  • 100
  • 183

1 Answers1

1

This will depend on whether you target iOS 5 or iOS 6.
iOS 5:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
   if ((orientation == UIInterfaceOrientationPortrait) ||
       (orientation == UIInterfaceOrientationLandscapeLeft))
       return YES;

       return NO;
}

iOS 6:

Set your default supported orientations in the App Summary and then in VC's you want to be different:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}

Apple Documentation for this HERE

See these questions for more info:

shouldAutorotateToInterfaceOrientation not being called in iOS 6

shouldAutorotateToInterfaceOrientation is not working in iOS 6

Community
  • 1
  • 1
LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • cool thank you :) I tried the ios6 code you supplied and found that after the view loads I can still rotate.. is that the right behaviour for the code? or do i need to implement the ios 5 code because that seems like it will work.. not that I have tried it yet. – HurkNburkS Mar 13 '13 at 02:19
  • It depends on if you are running this app with iOS 5 or iOS 6. They handle orientation differently – LJ Wilson Mar 13 '13 at 02:20
  • yea I am running in iOS6.. neither of the two statments are working for me.. it still allows me to rotate the view, for instance if I only define Portrait as the supported interface... I wounder if I have something not defined properly in my settings? (I am reading your other links now ) – HurkNburkS Mar 13 '13 at 02:24
  • I just cannot get this to work, I will keep reading on it over night.. then try some stuff in the morning again. – HurkNburkS Mar 13 '13 at 04:01