【发布时间】:2014-02-22 00:03:49
【问题描述】:
[我搜索了 Stackoverflow 并尝试了各种解决方案/建议,但尚未解决此问题。如果有人能指出我在这里缺少什么,非常感谢。]
我有一个带有多个选项卡的自定义 UITabBarController。每个都是一个 UINavigationController。其中一个 ViewX 是自定义 UINavigationController。
我希望 ViewX 不旋转为横向(仅支持 PortraitUp)。我能够做到这一点。但是,如果我在其他选项卡上处于横向模式并使用 ViewX 点击选项卡,我希望它旋转回纵向,但它保持横向。
CustomUITabController 有这样的代码:
-(BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
CustomUINavigationController 实现了这个:
-(BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
return (interfaceOrientation != UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
我什至尝试过:这只会将状态栏旋转为纵向,但视图仍保持为横向。
- (void)viewWillLayoutSubviews
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (interfaceOrientation != UIInterfaceOrientationPortrait)
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
}
【问题讨论】:
标签: ios iphone objective-c ios7 uitabbarcontroller