允许一个视图支持多个方向,而其他视图则不支持 iPhone
我遇到的情况是,我有多个视图通过 UITabBarController
控制。其中一个视图是通过 UINavigationController 控制的。应用程序应该只支持所有视图的纵向...除了一个单独的视图。该视图被推送到导航控制器的堆栈上,并且应该允许纵向和横向。
我已经尝试了我能想到的所有解决方案,但是,要么该解决方案不起作用,要么更糟糕的是完全无法预测。
有人以干净的方式解决这个问题吗?
I have a situation where I have multiple views controlled via UITabBarController
. One of those views is controlled via a UINavigationController
. The application should only support Portrait for all views... except one single solitary view. This view is pushed onto the stack of the navigation controller and should allow both portrait AND landscape.
I've tried every solution that I can think of but, either the solution just doesn't work or worse is completely unpredictable.
Has anybody solved this issue in a clean way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
presentModalViewController
或pushViewController
呈现的视图控制器应该支持任何方向,使用此方法:使用此方法,当您以横向方向呈现控制器时,它将正确也以横向方式出现。
The view's controller that you present either using
presentModalViewController
ORpushViewController
should support any orientation, using this method:With this method, when you present your controller in landscape orientation, it will correctly appear in landscape orientation, too.
我也有同样的问题。您必须为您的
UITabBarController
实现shouldAutorotateToInterfaceOrientation:
,并为您希望在所有视图控制器中支持的所有方向返回 YES。在相同的方法中,对于所有其他视图控制器,仅对于您想要在每个视图控制器中支持的方向返回 YES。要为 UITabBarController 实现
shouldAutorotateToInterfaceOrientation:
,您可以子类化 UITabBarController,但更简单的方法是在 UITabBarController 上实现一个类别并仅实现该方法:注意:在 Web 浏览器中键入;未编译。 :-)
您可以将其放在应用程序委托 .m 文件末尾。
我发现 UITabBarController 仅针对纵向返回 YES,这显然也会影响所有从属视图控制器。就我而言,我有一个从属视图控制器,我想支持纵向和横向,这解决了这个问题。
I had the same problem. You have to implement
shouldAutorotateToInterfaceOrientation:
for yourUITabBarController
and return YES for all the orientations you want to support across all your view controllers. And in the same method for all the other view controllers return YES only for the orientations you want to support in each of those view controllers.To implement
shouldAutorotateToInterfaceOrientation:
for your UITabBarController, you could subclass UITabBarController, but an easier way is to implement a category on UITabBarController and just implement that method:NB: Typed into a web browser; not compiled. :-)
You can put this right in your app delegate .m file at the end.
What I found was that UITabBarController returns YES only for portrait, which apparently also affects all the subordinate view controllers. In my case I had one subordinate view controller that I wanted to support both portrait and landscape and this solved it.
如果您在选项卡栏内有导航,则唯一的选择是将特定视图呈现为模式视图(选项卡栏要求所有视图支持自动旋转方向)。因此,基本上需要横向的单视图控制器应该实现
然后通过检测纵向方向并使用父级的方法,在模态视图控制器的相同方法中关闭模态视图
[self.parentViewController解雇ModalViewControllerAnimated:动画]
If you have the navigation inside of a tab bar, then the only option is to present the particular view as a modal view (tab bar requires all views to support the orientation to autorotate). So basically the single view controller, that needs landscape should implement
Then dismiss the modal view in the modal view controller's same method, by detecting portrait orientation and using the method for the parent
[self.parentViewController dismissModalViewControllerAnimated: animated]
对于iOS-6,我已经这样做了,它运行得很好
这会对你有帮助......
For iOS-6 , I have done this , it is running greatly
This will help you....