首先,我很抱歉再次提出同样的问题,这个问题已经在这个论坛上被问过很多次了。但是,我的问题是我已经尝试了所有建议的解决方案,但仍然没有解决我的问题。
我有一个ViewControllerA
在肖像模式下和ViewControllerB
在横向模式下。当设备从纵向变为横向时,我可以看到ViewControllerB
以横向模式打开,但当设备旋转回纵向模式时,ViewControllerA
显示但仍处于横向模式。有人可以帮助我了解如何以肖像模式显示它吗?
我尝试过以下操作,但没有任何效果对我有用:
在中添加了以下代码ViewControllerA
in viewWillAppear
:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
在此视图控制器中还添加了以下功能:
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
希望这可以通过使用supportedInterfaceOrientationsForWindow对您有所帮助
应用程序委托.h
@property () BOOL restrictRotation;
in AppDelegate.m
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
//restrictRotation is BOOL value
if(self.restrictRotation)//set the bool value to view controller which you want to load in landscape
return UIInterfaceOrientationMaskLandscape;
else
return UIInterfaceOrientationMaskAll;
}
//在需要的地方调用这个
必需的ViewController.m
-(void) restrictRotation:(BOOL) restriction
{
appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
//在ViewdidLoad()中
- (void)viewDidLoad
{
[super viewDidLoad];
[self restrictRotation:YES];//Set YES if required in Landscape mode
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)