当设备旋转到横向时如何打开新视图?
我有一个应用程序,它专注于纵向模式下的一堆视图控制器,但在特定的详细视图上,如果设备旋转到横向模式,我需要打开另一个视图。 因此,用户将以纵向模式查看信息视图,如果用户随后将设备旋转到横向模式,则会显示带有附加信息的新视图。如果用户旋转回纵向,则需要删除添加的视图,以便“原始”详细视图可见。 重要的是“原始”详细视图不会旋转为横向 - 仅在横向模式下打开新视图。
我尝试过使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用视图控制器检查方向是否已更改,是否更改了方向方法,如果其旋转到横向,则添加横向视图,并且当设备旋转到纵向时,从视图控制器的视图中删除视图。
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.
在
shouldAutorotateToInterfaceOrientation
中,您也可以对所有其他方向重复此操作。
in
shouldAutorotateToInterfaceOrientation
you can repeat this for all the other orientations as well.
使用 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.