iPad 视图显示为横向

发布于 2024-09-24 12:38:44 字数 1399 浏览 4 评论 0原文

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

应用程序中的大多数视图都被推送到带有隐藏导航栏的 UINavigationController 上。

当我在上述 UINavigationController 的顶视图控制器中添加以下代码时, 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}}

我找不到发生这种情况的任何可能原因,也无法弄清楚如何将视图重新定向为横向模式;我可以改变它的框架,但它的内容仍然是横向的。

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

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

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

I am working on an iPad app (which will not be submitted to the App Store) which supports only landscape mode.

Most of the views in the application are pushed onto a UINavigationController with a hidden navigation bar.

When I add the following code in the top view controller in the aforementioned UINavigationController, the new UINavigationController (navController) is created in portrait mode and appears sideways and off-screen.

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

I cannot find any possible reason for this to occur, nor can I figure out how to reorient the view to landscape mode; I can change its frame but its content is still sideways.

I tried adding the following to MyViewController.m to no avail:

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

I even tried adding this code to a UINavigationController subclass which did not work either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2024-10-01 12:38:44

通过将视图导航控制器添加为应用程序根视图的子视图,我能够使视图导航控制器正确定位自身。

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

此代码位于导航控制器的顶视图控制器中,它是根视图的子视图。

I was able to get the view navigation controller to orient itself correctly by adding it as a subview of my application's root view.

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

This code is in the top view controller of the navigation controller which is a subview of the root view.

甜柠檬 2024-10-01 12:38:44

不确定这是否有效,但您可以将此键添加到您的 Info.plist 中以指示您的应用程序支持的方向(至少,这将阻止它以纵向启动):

UISupportedInterfaceOrientations~ipad => (UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight)

Not sure if this will work, but you could add this key to your Info.plist to indicate what orientation your app supports (at least, this will prevent it from starting in portrait):

UISupportedInterfaceOrientations~ipad => (UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文