【发布时间】:2014-08-20 04:17:26
【问题描述】:
我无法保持当前的视图方向。在下面的设置中,我已经能够将第一个视图控制器锁定为纵向,将第二个视图控制器锁定为横向或纵向。但是,当我将第二个导航控制器/rootviewcontroller 添加到选项卡控制器时,整个项目的所有视图都将变为横向和纵向。无论我是否在第一个导航控制器到第二个导航控制器中实现相同的代码,都会发生这种情况
我希望能够保留我当前的视图控制器方向,同时添加一个额外的 navcontroller>viewcontroller
我在情节提要中有以下设置:
这就是我想要实现的目标:
tabbarcontroller应该支持所有方向,nav控制器支持所有方向,第一个视图控制器和表格视图控制器只支持纵向,第二个视图控制器支持横向和纵向。
这里是每个当前视图控制器的方法
TabViewController.m
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
NavController.m
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
First View Controller.m
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
第二视图控制器.m
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
在解决此问题时,我将不胜感激。它已成为我存在的祸根
【问题讨论】:
标签: ios objective-c ios7 uinavigationcontroller uitabbarcontroller