iOS7 - 设置 UITabBarController 的 selectedIndex 会破坏屏幕右侧边缘的触摸事件?

标签 ios7 uitabbarcontroller frame selectedindex

我遇到了一个奇怪的问题 UITabBarController在 iOS7 上,似乎找不到解决方法,所以欢迎任何帮助!

场景:

  • 在 iPad 上使用横向方向的基于导航的应用程序。
  • 应用程序由一个主视图和一个 UITabBarController 的第二个 View 组成。
  • TabBarController 有两个选项卡。
  • 第一个 View 有两个按钮 - 每个按钮对标签栏 Controller 执行一个 segue 并将不同的标签设置为选中。 (即 button1 选择第一个选项卡,而 button2 选择第二个选项卡)。
  • 设置选项卡在 prepareForSegue 中完成调用 setSelectedIndex在标签栏 Controller 上。

  • Simple storyboard that demonstrates the issue

    结果:

    在 iOS 7 上,我发现选项卡栏 Controller 中显示的 View 无法在 View 的右侧边缘注册任何触摸事件!所以在上图的storyboard中,不能点击屏幕右侧的UISwitch。

    我什至在 View 上附加了一个轻击手势识别器,并用它来记录可以触摸的屏幕区域——它似乎注册了大约 x=770 点的触摸事件。屏幕的剩余 1/4 是“不可触摸的”!

    在 segue 之后,如果您手动切换到另一个选项卡并再次切换回来,则触摸事件是“固定的”,并且完整 View 会再次响应触摸。

    这在 iOS 5/6 上似乎不是问题。

    任何帮助非常感谢:
  • 首先是什么导致这种情况发生(iOS7 错误/更改?)
  • 我还能如何解决这个问题?我试过调用setSelectedViewController以及使用 setSelectedIndex这似乎是一样的。

  • 提前致谢。

    最佳答案

    我最终向开发人员技术支持提出了这个问题,它看起来像一个错误。这是我从 Apple 收到的回复:

    标签栏 Controller 设置为包含您的 View Controller 的容器 View 未调整大小以考虑界面处于横向。显示 View Controller 时的尺寸为 768(宽度)x 1024(高度)。

    显示所选选项卡的 View 时, View 层次结构如下所示:

    UIWindow
        /* Navigation Controller */
        UILayoutContainerView
            UINavigationTransitionView
                UIViewControllerWrapperView
                    /* Tab bar controller */
                    UILayoutContainerView
                        UITransitionView
                            UIViewControllerWrapperView <-- Incorrectly sized.
                                /* MyViewController */
                                MyViewController.view
    

    UIViewControllerWrapperView 的大小不正确不会导致显示问题,因为即使 subview 超出其父 View 的范围,仍会显示 subview 。但是,事件路由要严格得多。屏幕右侧四分之一的事件永远不会路由到 View Controller 的 View ,因为 HitTest 在大小错误的 UIViewControllerWrapperView 处失败,其中事件超出 UIViewControllerWrapperView 的范围。

    作为一种解决方法,我将 UITabBarController 子类化,并在 viewWillAppear 中添加了以下内容:
    @implementation FixedIOS7TabBarController
    
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        // Fix the frame of the UIViewControllerWrapperView
        self.selectedViewController.view.superview.frame = self.view.bounds;
    }
    
    @end
    

    希望对其他人有所帮助....

    关于iOS7 - 设置 UITabBarController 的 selectedIndex 会破坏屏幕右侧边缘的触摸事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19156979/

    相关文章:

    ios - objective-C UITabBarItem : Custom Icon Color for All States with UIImageRenderingModeAlwaysOriginal

    java - java框架对象的问题

    uiview - ios 7 UiView框架问题

    objective-c - IOS UICollectionview动态改变单元格的高度

    objective-c - 在具有裁剪过渡的图像之间滚动

    ios - TabBarController 只加载黑屏?

    java - 小程序 isShowing() 与框架 isShowing()

    objective-c - 尝试链接 PushKit 框架时出现 Xcode 6.1 链接器错误

    iphone - AUIOClient_StartIO 尝试在后台播放时失败

    ios - 如何在AppDelegate中获取 StoryboardUITabBarController的指针