【发布时间】:2014-02-19 16:46:47
【问题描述】:
我有一个带有 4 个标签栏项目的 uitabbarcontroller,每个标签栏项目都有一个 uinavigationcontroller。
我只需要将一个 uitabbar 项目的方向锁定为纵向。所以我实现了以下代码:
创建了一个自定义标签栏控制器,并在其中添加了以下代码:
MainTabBarController.m
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
创建了一个自定义导航控制器以在其中一个 uitabbaritems 中使用,并在其中添加了以下代码:
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
对于自定义导航控制器中的 uiviewcontroller,我添加了以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
上面的代码工作正常。我的问题是,如果您在设备已经处于横向模式时转到选项卡栏项(其方向锁定为 Protrait),则方向将更改为横向。谁能帮我解决我的问题。
谢谢, 阿南德。
【问题讨论】:
标签: uitabbarcontroller orientation landscape uitabbaritem portrait