UITabBarController和旋转iOS6
在美国的快乐的阵亡将士纪念日!UITabBarController和旋转iOS6
我是iOS和Objective-C编程的新手,几个星期前,我继承了一个为iOS 5设计的iPad应用程序开发。现在除了iOS 6中的旋转之外,我现在拥有一切工作。我知道iPad应用程序应该旋转到默认的每个方向(这就是我想),但我的不是。一切都在iOS 5中完美旋转,并且我可以让我的启动画面在iOS 6中完美旋转,但仅此而已。我无法获得活动(一旦你点击启动画面)就可以正常旋转。
我已经搜索了*和其他网站来弄清楚我必须做什么,所以我知道在任何特定的ViewController中实现-(BOOL)shouldAutorotate
和-(NSUInteger)supportedInterfaceOrientations
来控制该视图的方向行为。我已经读过,在一个VC中具有不同的旋转行为会影响整个应用程序。所以我确保每个我能找到的VC现在都会实现这两种iOS 6方法,分别返回YES
和UIInterfaceOrientationMaskAll
。这没有用。我阅读了关于在这些方法中返回self.tabBarController.shouldAutorotate
和self.tabBarController.supportedInterfaceOrientations
以确保标签栏旋转行为一致,但这不起作用。我已阅读关于实现一个类(UITabBarController + autoRotate.m和.h),实现这两个方法,并没有奏效。我读过关于继承的tabBarController,我认为我的代码做的是:在我的appDelegate,我叫
[myWindow setRootViewController:activityViewController]
,
其中activityViewController是类BicycleFamilyAcitivityViewController,这是从
@interface BicycleFamilyActivityViewController : UIViewController <UITabBarControllerDelegate>
当我调查使用iOS 6模拟器成功启动屏幕旋转过程中所调用的内容时,我注意到BicycleFamilyAcitivityViewController中的这两个实现方法正在被调用(实际上每次调用两次) nd -(void)willAnimateRotationToInterfaceOrientation:duration
也是如此。当我在查看活动时尝试旋转时(单击启动画面后),这两种方法仅调用一次,并且不调用-(void)willAnimateRotationToInterfaceOrientation:duration
。在这两种情况下,调用AppDelegate的-(NSUInteger)application:supportedInterfaceOrientationsForWindow
方法。
有关如何让轮换在整个应用程序中工作的任何建议?即使它只是指向我还没有看到(或完全理解)的*的答案,我将非常感激。
非常感谢提前!
伯尼
**在寻找项目的VC类,我确信考虑到实施的iOS 5的旋转方法的类:-(BOOL)shouldAutorotateToInterfaceOrientation:interfaceOrientation
有人在内部找出问题所在。我想我会发布答案,以帮助任何有类似困境的人。
我曾尝试过(除其他之外)是:将我的appDelegate类中的UIWindow设置为UIViewController的子类(BicycleFamilyAcitivityViewController)的实例。在我的appDelegate中,我有:
[myWindow setRootViewController:activityViewController];
其中activityViewController是UIViewController的子类的一个实例。
但我应该通过委托创建了一个额外的UIWindow,然后当我构建我的TabBarController时,将TabBarController(tbc)指定为它的根VC。在我的主视图控制器类中,我有一个buildTabBarController
函数。所以这两条线的功能允许我的轮换工作:
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow setRootViewController:tbc];
希望这有助于!
在iOS 6中的定位功能已经改变。您的设置应该像这样在你的viewControllers:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
-(BOOL)shouldAutorotate {
return TRUE;
}
UIInterfaceOrientationMaskAll
是所有取向更多信息here。
谢谢约翰, 我已经在viewControllers中实现了这些方法,保存为 preferredInterfaceOrientationForPresentation。我在每个viewController中添加了这个方法,以防造成差异。但它不是 。 我知道,个别viewControllers没有 shouldAutorotate&supportedInterfaceOrientations调用。我想如果我能让系统进行这些调用,一切都应该落实到位(因为旋转在iOS 5中完美运行)。 其他建议? – Bernie
我仍然会投票你的答案,因为它是一个正确的;但我需要15的声望才能这样做! – Bernie
我还没有弄明白。我的rootVC(BicycleFamilyActivityViewController)中的shouldAutoRotate和supportedInterfaceOrientations方法在循环时被调用,它们返回YES和UIInterfaceOrientationMaskAll,但似乎并没有旋转tabbar或任何东西。我可以从这些方法写出调用subViewControllers中相应的方法,但这没有帮助。 – Bernie