iOS7 - 设置UITabBarController的selectedIndex会在屏幕右边缘打破触摸事件? [英] iOS7 - Setting selectedIndex of UITabBarController breaks touch events along right-hand edge of screen?

查看:86
本文介绍了iOS7 - 设置UITabBarController的selectedIndex会在屏幕右边缘打破触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've hit a weird problem with UITabBarController on iOS7 and can't seem to find a workaround, so any help would be welcome!

场景:


  • 在iPad上使用横向方向的基于导航的应用。

  • App包含一个主视图,第二个视图是一个UITabBarController。

  • TabBarController有两个选项卡。

  • 第一个视图有两个按钮 - 每个按钮对标签栏控制器执行一个segue,并设置一个不同的选项卡。 (即button1选择第一个选项卡,button2选择第二个选项卡)。

  • 通过调用<设置选项卡在 prepareForSegue 中完成标签栏控制器上的code> setSelectedIndex 。

  • Navigation-based app using landscape orientation on iPad.
  • App consists of a main view, and a second view which is a UITabBarController.
  • TabBarController has two tabs.
  • First view has two buttons - each button performs a segue to the tab bar controller and sets a different tab as selected. (i.e. button1 selects the first tab, and button2 selects the second tab).
  • Setting the tab is done in prepareForSegue by calling setSelectedIndex on the tab bar controller.

结果:

在iOS 7上我发现标签栏控制器中显示的视图无法在视图的右边缘注册任何触摸事件!因此,在上面显示的故事板中,屏幕右侧的UISwitch无法点击。

On iOS 7 I am finding that the view shown in the tab bar controller fails to register any touch events along the right-hand edge of the view! So in the storyboard shown above, the UISwitch on the right side of the screen cannot be tapped.

我甚至在视图中附加了一个轻敲手势识别器,并用它来记录可以触摸的屏幕区域 - 似乎将触摸事件注册到大约x = 770分。屏幕剩余的1/4是不可触摸的!

I've even attached a tap gesture recognizer to the views and used it to log the area of the screen that can be touched - it seems to register touch events up to about x=770 points across. The remaining 1/4 of the screen is 'untouchable'!

在segue之后,如果您手动切换到另一个标签并再次切换回来,则触摸事件为'已修复'并且完整视图会再次响应触摸。

After the segue, if you manually switch to the other tab and switch back again, the touch events are 'fixed' and the full view responds to touches again.

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

This doesn't seem to be a problem on iOS 5 / 6.

任何帮助非常感谢:


  1. 首先导致这种情况发生的原因(iOS7错误/更改) ?)

  2. 我还能解决这个问题吗?我试过调用 setSelectedViewController 以及使用 setSelectedIndex ,这似乎是一样的。

  1. What is causing this to happen in the first place (iOS7 bug / change?)
  2. How else can I work around this? I've tried calling setSelectedViewController as well as using setSelectedIndex and this seems to be the same.

提前致谢。

推荐答案

我最终了通过开发者技术支持提高了这一点,它看起来像一个bug。这是我从Apple那里得到的回复:

I ended up raising this with Developer Tech Support, and it looks like a bug. This is the response I got back from Apple:

标签栏控制器设置为包含视图控制器的容器视图没有调整大小以考虑接口是否存在在横向方向。显示视图控制器时的尺寸为768(宽度)x 1024(高度)。

The container view that the tab bar controller sets up to contain your view controller is not being resized to account for the interface being in landscape orientation. It's dimensions at the time your view controller is displayed are 768 (width) x 1024 (height).

显示所选标签视图时,视图层次结构如下所示:

The view hierarchy looks like this when the selected tab's view is displayed:

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

UIViewControllerWrapperView的大小不正确不会导致显示问题,因为即使子视图超出其超视图范围,它们仍会显示。但是,事件路由要严格得多。屏幕右侧四分之一的事件永远不会路由到视图控制器的视图,因为命中测试在错误大小的UIViewControllerWrapperView中失败,其中事件落在UIViewControllerWrapperView的边界之外。

The incorrect size of UIViewControllerWrapperView does not cause a display problem because subviews are still displayed even if they are outside their superview's bounds. However, event routing is much more strict. Events on the right quarter of the screen are never routed to your view controller's view because the hit test fails at the wrongly-sized UIViewControllerWrapperView where the event falls outside UIViewControllerWrapperView's bounds.

作为一种解决方法,我将UITabBarController子类化,并在viewWillAppear中添加以下内容:

As a workaround, I subclassed UITabBarController, and added the following in 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

希望能帮到别人。 ......

Hope that helps someone else....

这篇关于iOS7 - 设置UITabBarController的selectedIndex会在屏幕右边缘打破触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆