gpt4 book ai didi

ios - 如何设置第二个 UIWindow 的方向

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

我的主要 ViewController viewDidLoad 函数中有以下代码

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


nav = [[NavWithAutoRotateViewController alloc] initWithRootViewController:self];

[window addSubview:[nav view]];
[window makeKeyAndVisible];


[[self navigationController] setNavigationBarHidden:YES];

我的 ipad 应用程序当前设置为仅在横向模式下工作,我正在使用这个新窗口显示快速查看文档并允许导航栏提供后退按钮和保存文档选项。主要问题是新的 UIWindow 方向与我的主要应用程序 UIWindow 不匹配。

我在上面有一个名为 NavWithAutoRotateController 的自定义 UINavigationController,这里是该 Controller 的代码。

-(id)init
{
if(self)
{
// _supportedInterfaceOrientatoin = UIInterfaceOrientationMaskLandscape;
// _orientation = UIInterfaceOrientationLandscapeLeft;
}


return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotate
{
return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}


// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskLandscape;
}

最佳答案

我想我有一个解决方案。问题似乎在于将 UIViewController 分配给额外的 UIWindow 中的 rootViewController

如果您只是假设您可以使用主 UIWindow 正在使用的相同 View Controller ,然后将内容添加为新 UIWindow 的 subview ,则存在方向问题。

为了解决这个问题,我做了以下事情:

UIWindow *newWindow = [[UIWindow alloc] initWithFrame: [UIApplication sharedApplication].keyWindow.frame];
newWindow.windowLevel = UIWindowLevelStatusBar+1;
// You can use a view controller instantiated from a xib or storyboard here if you want.
// Just don't use the view controller already set as a UIWindow's rootViewController.
UIViewController *newViewController = [[UIViewController alloc] init];
newWindow.rootViewController = newViewController;
[newWindow makeKeyAndVisible];
// Add something to the new UIWindow. Can use the new UIViewController's view:
[newViewController.view addSubview: myContentView];
// Or could add it as subview of UIWindow: - either works.
[newWindow addSubview: myContentView];

这样做似乎已经解决了围绕旋转的所有奇怪问题。希望这会有所帮助。

关于ios - 如何设置第二个 UIWindow 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18256381/

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