gpt4 book ai didi

ios - 标签栏 Controller : Orienting views in different orientations

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:26 25 4
gpt4 key购买 nike

我无法保持当前的 View 方向。在下面的设置中,我已经能够将第一个 View Controller 锁定为纵向,将第二个 View Controller 锁定为横向或纵向。但是,当我将第二个导航 Controller /rootviewcontroller 添加到选项卡 Controller 时,整个项目中的所有 View 都将变为横向和纵向。无论我是否将第一个导航 Controller 中的相同代码实现到第二个导航 Controller ,都会发生这种情况

我希望能够在添加额外的 navcontroller>viewcontroller 的同时保留我当前的 View Controller 方向

我在 Storyboard中有以下设置: enter image description here

这就是我要实现的目标: enter image description here

tabbarcontroller 应该支持所有方向,nav Controller 支持所有方向,第一个 View Controller 和表格 View Controller 只支持纵向,第二个 View Controller 支持横向和纵向。

这里是每个当前 View Controller 的方法

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;
}

第二 View Controller .m

-(BOOL)shouldAutorotate

{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

return UIInterfaceOrientationLandscapeLeft;
}

如能协助解决此问题,我将不胜感激。它已成为我存在的祸根

最佳答案

看来您已经将导航和标签栏 Controller 都进行了子类化。您可以在运行时仅使用委托(delegate)协议(protocol)来控制方向,而不是这样做。

– tabBarControllerSupportedInterfaceOrientations:
– tabBarControllerPreferredInterfaceOrientationForPresentation:

– navigationControllerPreferredInterfaceOrientationForPresentation:
– navigationControllerSupportedInterfaceOrientations:

您可以将您的逻辑放在那些方法中,我认为这会更好地实现更清晰的实现,而不是子类化。容器 View Controller 通常接管单个 vc 旋转实现。

关于ios - 标签栏 Controller : Orienting views in different orientations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24479184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com