HurkNburkS
HurkNburkS

Reputation: 5510

different UIViewController Orientations depending on which view the user is in

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.

Upvotes: 0

Views: 132

Answers (1)

LJ Wilson
LJ Wilson

Reputation: 14427

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

Upvotes: 1

Related Questions