gpt4 book ai didi

ios - 强制 iOS 设备改变方向

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:57 25 4
gpt4 key购买 nike

首先,我很抱歉再次提出同样的问题,这个问题已经在这个论坛被问过很多次了。但是,我的问题是我已经尝试了所有建议的解决方案,但仍然没有解决我的问题。

我在 Potrait 模式下有一个 ViewControllerA,在横向模式下有一个 ViewControllerB。当设备从纵向变为横向时,我可以看到 ViewControllerB 在横向模式下打开,但是当设备旋转回纵向模式时,显示 ViewControllerA 但仍处于横向模式。谁能帮助我了解如何以肖像模式显示它?

我尝试了以下操作,但对我没有任何效果:

viewWillAppearViewControllerA 中添加了以下代码:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

在此 View Controller 中还添加了以下功能:

- (BOOL)shouldAutorotate
{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

最佳答案

希望这对您使用 supportedInterfaceOrientationsForWindow 有帮助

Appdelegate.h

@property () BOOL restrictRotation;

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;
}

//在你需要的地方调用它

requiredViewController.m

-(void) restrictRotation:(BOOL) restriction
{

appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}

//View中的didLoad()

- (void)viewDidLoad
{
[super viewDidLoad];
[self restrictRotation:YES];//Set YES if required in Landscape mode
}

关于ios - 强制 iOS 设备改变方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com