关于iOS app的设备方向支持的问题

来源:互联网 发布:郜艳敏事件知乎 编辑:程序博客网 时间:2024/05/22 10:39

关于iOS app的设备方向支持的问题

之前做过一个app,是一个UITabBarController 下面有若干个view,好,我想让这个app支持设备3向旋转。

把第一个view的方向函数写成

(BOOL)shouldAutorotateToInterfaceOrientation:      (UIInterfaceOrientation)interfaceOrientation{    // Return YES for supported orientations    return (interfaceOrientation !=                     UIInterfaceOrientationPortraitUpSideDown);}

运行,这个view并不支持横向,于是把所有的view都设置一遍后,整个app就支持3向了。

初步结论:噢,看来要把UITabBarController下的每个view都设置成某,整个controller才支持方向。

现在做另一个app的时候,我的结构是,UITabBarController下有俩tab,每个tab下是个NavigationController,这里面是UITableView,选中某个row后push进来一个view。

我的需求是,TableView是仅仅支持单向的,而push进来的view(里面是web,看视频)我希望仅仅支持横向(左或右)。有没有可能实现?

以下是实验过程:

1、把view设置成左或右,失败。

2、会不会是因为他的上级不支持左右,所以失败?于是有个猜想:如果AController下面有BController和CController,是不是A的支持方向需要是BC的并集,B或C必须是A的子集?其实不是这样,因为(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation函数是ViewController的方法,和tabBarController,NavigationController没关系!

3、在IB里可以设置UITabBarController的方向,2选1,横向或纵向,这显然不符合需求。

4、我把TableView设置成3向,push进来的view设置成单向,ok,没有问题。

5、tableview单向,push的view3向,失败。

最后,万能的stack over flow:

Make sure all of your parent views have autoresizesSubviews = YES. You may need to do this in code if you haven’t set springs and struts in IB for all of your views.(Xcode4.1里在IB的属性选择器里有,默认是yes的。)

A couple other things to be aware of:

  1. A UINavigationController will only autorotate if its root view controller is also set to autorotate.
  2. A UITabBarController will only autorotate if all of its view controllers are set to autorotate.

我日。

ps:how to use [code][/code]…

原创粉丝点击