【问题标题】:iPad UIModalPresentationFormSheet with UITabBarController's moreNavigationController edit mode issueiPad UIModalPresentationFormSheet 与 UITabBarController 的 moreNavigationController 编辑模式问题
【发布时间】:2012-09-05 18:03:18
【问题描述】:

这似乎是一个错误,但我想知道是否有人能想到解决方法。

在 iPad 上,您将视图控制器呈现为 UIModalPresentationFormSheet。这个视图控制器扩展了 UITabBarController 并且有足够的控制器来自动显示“更多”标签栏按钮。一旦您点击更多按钮,它将正确显示列表,但是一旦您点击“编辑”,它就会显示比实际表单更大的编辑视图(在表单内裁剪),导致内容超出视图,包括带有“完成”按钮的工具栏。关闭的唯一方法是强制退出应用程序。

为了验证它不是特定于我的应用程序的东西,我启动了一个单视图项目,并展示了一个简单的模态视图。此模态视图控制器扩展了 UITabBarController 并具有以下 init 方法:

- (id)init {
    self = [super init];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationFormSheet;
        NSMutableArray *controllers = [NSMutableArray array];
        for (int i = 0; i< 15; i++) {
            UIViewController *vc = [[UIViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
            vc.title = [NSString stringWithFormat:@"view %i", i];
            [controllers addObject:nav];
        }
        self.viewControllers = controllers;
    }
    return self;
}

我也尝试将 modalPresentationStyle 添加到 moreNavigationController 而没有任何变化。

【问题讨论】:

    标签: ipad uitabbarcontroller


    【解决方案1】:

    早上好,头晕。

    你提出了一个很好的挑战。这里有一个解决方案,可能有点硬核,但确实有效。

    我已经按照你写的那样做了——继承了 UITabBarController 并将其呈现为模态视图控制器。并遇到同样的问题。在“更多”屏幕中点击“编辑”按钮时出现UITabBarCustomizeView,并且它的框架不足。

    所以我做了以下事情。我已经让 MyModalTabBarVC 成为自己的代表并实现了tabBarController:willBeginCustomizingViewControllers: 方法:

    - (void)tabBarController:(UITabBarController *)tabBarController     
    willBeginCustomizingViewControllers:(NSArray *)viewControllers
    {
        UIView *modalView = self.view;
        CGRect bounds = modalView.bounds;
    
        UIView *customizationView   = [[modalView subviews] objectAtIndex:1];
        UIView *customizationNavBar = [[customizationView subviews] objectAtIndex:0];
    
        CGRect navBarFrame = [customizationNavBar frame];
        navBarFrame.size.width = bounds.size.width;
        customizationNavBar.frame = navBarFrame;
        customizationView.frame   = bounds;
    }
    

    所以当这个方法被调用时,UITabBarCustomizeView 已经被创建了。并且可以手动更改错误的框架。如果您在开始时登录po [self.view subviews],您将获得:

    (id) $1 = 0x06c6a940 <__NSArrayM 0x6c6a940>(
    <UITransitionView: 0xd744ab0; frame = (0 0; 540 571); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xd744b50>>,
    <UITabBarCustomizeView: 0x6c5e570; frame = (0 -384; 768 1004); animations = { position=<CABasicAnimation: 0x6c569a0>; }; layer = <CALayer: 0x6c618d0>>,
    <UITabBar: 0xd744110; frame = (0 571; 540 49); autoresize = W+TM; layer = <CALayer: 0xd742b80>>,
    )
    

    PS。此解决方案不修复动画。从日志中可以看出,损坏的动画已经创建并收费。我希望取消它并适当地添加一个新的不会有问题。

    【讨论】:

      【解决方案2】:

      模态视图的 viewController 一定是导致故障的原因。

      您可以尝试:

      1. 编辑时隐藏标签栏,完成按钮后取消隐藏 被按下。
      2. 为视图控制器创建一个自定义工具栏,可以这样做 使用 UIView,使其始终位于视图顶部。
      3. 调整各个选项卡的大小。最好的方法是创建你的 连接了 UIViewController 和 IBActions 的自定义标签栏 到带有 IBOutlets 的 UIButtons。

      为什么 modalPresentationStyle 中有这么多标签?我个人会改用 push segue。

      尝试推送到它们自己的导航控制器下的一组新视图控制器。标签栏将有更多空间。要返回,请在弹出推送的工具栏中放置一个返回按钮,或者返回到原来的位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-11
        • 1970-01-01
        • 2018-01-26
        • 2011-07-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多