【发布时间】:2015-03-15 13:07:27
【问题描述】:
我有一个 iOS 应用程序,我在其中将 UINavigationController 作为子视图控制器添加到主屏幕。它是垂直排列的,因此导航控制器占据了主视图高度的底部并且是全宽的。导航正上方有一个按钮(实际上是一个带有点击识别器的自定义视图),用于隐藏和显示它;当导航隐藏时,按钮位于主屏幕底部,当显示导航时,按钮位于导航栏顶部的正上方。
问题在于导航栏似乎拦截了对按钮底部 10 点左右的触摸。这是为什么呢?
添加孩子的代码如下所示:
UIViewController *root = [[[UIViewController alloc]init]autorelease]; //some VC
UINavigationController *nav = [[[UINavigationController alloc]initWithRootViewController:root]autorelease];
[self addChildViewController:nav];
CGRect rect = self.view.frame;
CGFloat height = 500;
nav.view.frame = CGRectMake(0, rect.size.height - height, rect.size.width, height);
[self.view addSubview:nav.view];
[nav didMoveToParentViewController:self];
//Now the button
UIView *view = [[[UIView alloc]initWithFrame:CGRectZero]autorelease];
view.backgroundColor = [UIColor greenColor];
[self.view addSubview:view];
view.frame = CGRectMake(0, rect.size.height - 500 - 40, rect.size.width, 40);
UITapGestureRecognizer *recog = [[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onToggleSplit)]autorelease];
[view addGestureRecognizer:recog];
onToggleSplit 使导航上下动画。当它启动时,点击“按钮”底部的 10 个点左右什么也不做。我尝试在我的自定义“按钮”视图上覆盖 touchesBegan,但它甚至没有被调用。
如果我为子 VC 使用常规的 UIViewController(或其子类),按钮会按预期响应。
【问题讨论】:
-
当你给
nav.view上色时,它不会和按钮重叠,是吗?
标签: ios uinavigationcontroller uicontainerview