• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - TabBarController : Orienting views in different orientations

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:32:32 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

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

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

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



Best Answer-推荐答案


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

– tabBarControllerSupportedInterfaceOrientations:
– tabBarControllerPreferredInterfaceOrientationForPresentation:

– navigationControllerPreferredInterfaceOrientationForPresentation:
– navigationControllerSupportedInterfaceOrientations:

你可以把你的逻辑放在那些我认为有一个更清晰的实现而不是子类化的方法中。容器 View Controller 通常接管单个 vc 旋转实现。

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap