iOS(iPhone/iPad)SDK-如何从代码中旋转应用程序(UITabBarController有问题)
在我的应用程序委托中,我在UITabBarController中重写了shouldAutorotateToInterfaceOrientation(别担心,我没有将其子类化!;)。我是这样做的: (AppDelegate.h的底部): (AppDelegate.m的底部): 目前我有它,这样当我进入一个特定的选项卡(索引4)时,当设备旋转时,它不会旋转到横向(这是我想要的)。尽管问题是,如果应用程序已经是横向的,并且您点击该视图,那么它就是横向的(我希望它保持纵向)(注意:如果我允许,应用程序可以正常旋转,因此使用iOS(iPhone/iPad)SDK-如何从代码中旋转应用程序(UITabBarController有问题),iphone,ios,cocoa-touch,ipad,sdk,Iphone,Ios,Cocoa Touch,Ipad,Sdk,在我的应用程序委托中,我在UITabBarController中重写了shouldAutorotateToInterfaceOrientation(别担心,我没有将其子类化!;)。我是这样做的: (AppDelegate.h的底部): (AppDelegate.m的底部): 目前我有它,这样当我进入一个特定的选项卡(索引4)时,当设备旋转时,它不会旋转到横向(这是我想要的)。尽管问题是,如果应用程序已经是横向的,并且您点击该视图,那么它就是横向的(我希望它保持纵向)(注意:如果我允许,应用程序可
应该自动旋转指向器FaceOrientation
不会真正解决问题(或者可能会解决问题))
我发现这个UITabBarController委托方法:
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)tabViewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:tabViewController];
if (indexOfTab == 4) {
//FILL GAP HERE!
}
}
我试过这个:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
但它只会旋转状态栏,而不是整个应用程序。UITabBarController中是否有某种方法(或任何东西)可以将其旋转到纵向以填补上面的空白
抱歉,如果它对任何人来说都不太容易混淆。只需对不希望旋转的选项卡中使用的视图控制器实现shouldAutorotateToInterfaceOrientation:toInterfaceOrientation:并确保它对无效方向返回否.使用了
transform
和setStatusBaroOrientation
——虽然它有一些副作用(现在必须这样做)。我试过了,但没用。似乎shouldAutorotateToInterfaceOrientation
只在它要旋转时调用,而不是在它已经旋转时调用。
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)tabViewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:tabViewController];
if (indexOfTab == 4) {
//FILL GAP HERE!
}
}
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];