Tabbar Nav app, allowing one view to rotate while others do not

懵懂的女人 提交于 2020-01-05 14:29:52

问题


I have a tab bar application in which i have 3 diffrent views each with there own view controller.

In the tab bar code i have this, to handle rotation.

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

Then in the 2nd view controller that i want to rotate depending on device orientation i have:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

And For the other two views that i do not want to rotate i have this method set.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

The PROBLEM: so this works fine in view 1 and view 3 when u rotate the device they stay in portrait mode which is desired. When in view 2 i rotate to landscape, the view does as expected and rotates to landscape. BUT when click view 1 or view 3 tab while in lanscape mode in view 2, View 1 and View 3 are in landscape mode.

I can't figure out how to force them in portrait even if view 2 rotates to lanscape.

Any one know how to do this?


回答1:


There's a big discussion[1] on this dating back from 2008 until now (look at comments down a few pages) -- summarily it seems like

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

or

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

or

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

will let you force it to landscape -- you would want to do this when the user goes back to your landscapey view(s) programmatically.

[1] iPhone app in landscape mode, 2008 systems



来源:https://stackoverflow.com/questions/3166050/tabbar-nav-app-allowing-one-view-to-rotate-while-others-do-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!