Teddy13
Teddy13

Reputation: 3854

Not rotating only one view in a tab bar view controller

I know this question has been kind of asked and have looked into the solutions that others have posted but still feel quite confused on the topic so I apologize if this really is a "noob" question.

So I have a tab bar view controller and I have 2 views that should autorotate and one that never should. My understanding is that shouldAutorotateToInterfaceOrientation needs to always return YES; in order for any view controllers to autorotate. So if this is the case, how would I get only one to NOT rotate but keep the orders rotating?

Thank you very much!

P.S. I tried this from a different post found here: How to prevent the view controllers in a tab bar controller from rotating? but with no luck. The answer from that post is posted below

"This is a commonly reported "bug" - however a good workaround is to force the shouldAutorotateToInterfaceOrientation: selector to be triggered as follows:"

   - (void)viewDidAppear:(BOOL)animated {
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
} 

Upvotes: 0

Views: 932

Answers (1)

John Estropia
John Estropia

Reputation: 17500

The behavior you're aiming for conflicts with the rotation rules of UITabBarControllers. You mentioned it yourself:

shouldAutorotateToInterfaceOrientation needs to always return YES in order for any view controllers to autorotate.

But what you want is for one of the view controllers to return NO, which violates that rule. So to answer your question, you will have to implement your own custom view controller container (or a custom view).

There's a good reason this restriction was placed added to UITabBarControllers. Tabs with different rotation rules will be annoying to user since the screen will keep rotating on them each time they change tabs.

Now if I were you, I'll allow all my tabs to rotate, then present the non-rotating view as a modal view.

Upvotes: 1

Related Questions