gpt4 book ai didi

objective-c - iPad View 出现在侧面

转载 作者:行者123 更新时间:2023-11-29 13:51:15 24 4
gpt4 key购买 nike

我正在开发仅支持横向模式的 iPad 应用程序(不会提交到 App Store)。

应用程序中的大部分 View 都被推送到带有隐藏导航栏的 UINavigationController。

当我在上述 UINavigationController 的顶 View Controller 中添加以下代码时, UINavigationController (navController) 以纵向模式创建,并出现在侧面和屏幕外。

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
// viewController.view is landscape in MyView.xib

// myViewController is created in landscape mode
NSLog(@"%@", NSStringFromCGRect(myViewController.view.frame)); // {{0, 0}, {1024, 704}}

UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:myViewController];

// navController is created in portrait mode (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{0, 0}, {768, 1024}}

[self presentModalViewController:navController animated:YES];

// navController is shifted off-screen after it is presented modally (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{1024, 0}, {748, 1024}}

我找不到发生这种情况的任何可能原因,也不知道如何将 View 重新定向为横向模式;我可以更改它的框架,但它的内容仍然是横向的。

我尝试将以下内容添加到 MyViewController.m 但无济于事:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return !UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

我什至尝试将这段代码添加到 UINavigationController 子类中,但它也不起作用。

最佳答案

通过将 View 导航 Controller 添加为应用程序 Root View 的 subview ,我能够使 View 导航 Controller 正确定位。

MyRootViewController *myRootViewController = [[[UIApplication sharedApplication] delegate] myRootViewController];
[myRootViewController presentModalViewController:navController animated:YES];

此代码位于导航 Controller 的顶 View Controller 中,它是 Root View 的 subview 。

关于objective-c - iPad View 出现在侧面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3780837/

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