我遇到了一个奇怪的问题 UITabBarController
在 iOS7 上,似乎找不到解决方法,所以欢迎任何帮助!
场景:
prepareForSegue
中完成调用 setSelectedIndex
在标签栏 Controller 上。 结果:
在 iOS 7 上,我发现选项卡栏 Controller 中显示的 View 无法在 View 的右侧边缘注册任何触摸事件!所以在上图的storyboard中,不能点击屏幕右侧的UISwitch。
我什至在 View 上附加了一个轻击手势识别器,并用它来记录可以触摸的屏幕区域——它似乎注册了大约 x=770 点的触摸事件。屏幕的剩余 1/4 是“不可触摸的”!
在 segue 之后,如果您手动切换到另一个选项卡并再次切换回来,则触摸事件是“固定的”,并且完整 View 会再次响应触摸。
这在 iOS 5/6 上似乎不是问题。
任何帮助非常感谢:
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/