目前正在开发一个使用标签栏控制器的应用程序。该应用程序根本不会旋转到横向模式 - 所有视图都继承自 baseVieController,在这里我已经实现了:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return true;
}
现在我知道 tabBar 控制器不会旋转,除非它的所有子视图都支持视图尝试旋转到的方向 - 我的问题是:如果我不在所有子视图中实现 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法,即使我没有将其指定为所需的方向,它是否会将这些子视图锁定为纵向模式?因此将整个 tabBar 控制器锁定为纵向。我知道以前曾有人问过类似的问题,但我找不到这个具体问题的答案。提前致谢。
您可以旋转视图,只需要像下面这样覆盖:
只需在要旋转的视图控制器类中添加代码(此处为“SampleClassName”)
@interface UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end
@implementation UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([self.selectedViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *navController = (UINavigationController *) self.selectedViewController;
if ([[navController visibleViewController] isKindOfClass:[SampleClassName class]])
return YES;
}
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)