当设备旋转到横向时如何打开新视图?

发布于 2024-10-19 11:07:57 字数 327 浏览 8 评论 0原文

我有一个应用程序,它专注于纵向模式下的一堆视图控制器,但在特定的详细视图上,如果设备旋转到横向模式,我需要打开另一个视图。 因此,用户将以纵向模式查看信息视图,如果用户随后将设备旋转到横向模式,则会显示带有附加信息的新视图。如果用户旋转回纵向,则需要删除添加的视图,以便“原始”详细视图可见。 重要的是“原始”详细视图不会旋转为横向 - 仅在横向模式下打开新视图。

我尝试过使用shouldAutorotateToInterfaceOrientation:并设法让它打开一个viewController,但它没有在横向视图中显示,所以它看起来一团糟,而且当我旋转回纵向模式时,我很难让视图消失。

我该怎么做?

I have an application which is focused around a bunch of viewControllers in portraitmode, but on a specific detail view i need to open another view if the device is rotated to landscape mode.
So the user will look at the information view in portraitmode and if the user then rotates the device to landscapemode then a new view is displayed with additional information. If the user rotates back to portrait then the added view needs to be removed so the "original" detailview is visible.
It's important that the "original" detailview is not rotated to landscape - Only open a new view in landscape mode.

I've tried using shouldAutorotateToInterfaceOrientation: and managed to have it open a viewController, but it's not being shown in landscape view so it looks all messed up plus I'm having some trouble getting the view to disappear when i rotate back to portraitmode.

How do i do this?

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

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

发布评论

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

评论(3

哭泣的笑容 2024-10-26 11:07:57

使用视图控制器检查方向是否已更改,是否更改了方向方法,如果其旋转到横向,则添加横向视图,并且当设备旋转到纵向时,从视图控制器的视图中删除视图。

Check if the orientation has changed using the View controllers did change orientation methods and if its rotated to landscape add ur landscape view and when the device is rotated to portrait remove the view from the view controller's view.

陈独秀 2024-10-26 11:07:57

shouldAutorotateToInterfaceOrientation 中,

if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:@"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}

您也可以对所有其他方向重复此操作。

in shouldAutorotateToInterfaceOrientation

if(UIInterfaceOrientation == UIInterfaceOrientationPortrait){
NewView *newViewController = [[NewView alloc]initWithNib:@"NewView" bundle:nil];
[self.navigationController pushViewController:newViewController animated:NO];
}

you can repeat this for all the other orientations as well.

往日情怀 2024-10-26 11:07:57

使用 shouldAutoRotate 不起作用,因为打开的视图将以纵向模式而不是横向模式打开。

我最终得到了在子视图中使用 beginGenerateDeviceOrientationNotifications 和 shouldAutoRotate 的解决方案。

Using shouldAutoRotate didn't work since the view that gets opened will be opened in portraitmode and not landscape.

I ended up with a solution using beginGeneratingDeviceOrientationNotifications and shouldAutoRotate in the subview.

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