触摸未调用导航栏~8像素内的事件 [英] Touch events within ~8 pixels of nav bar not called
问题描述
我有一个带有三个按钮的应用程序(实际上是 UIView
)在水平下面导航栏。
I have an application with three buttons (actually UIView
's) laid out horizontally underneath the navigation bar.
这三个按钮的大小足够大(例如,比后退按钮大),但是当命中大致位于前三分之一时,它们不会响应触摸。
The three buttons are of substantial enough size (larger than the back button, for example), however they won't respond to touches when the hit is in the top third part, roughly.
我知道导航栏正下方的这个区域对于后退按钮和其他UINavigation项目来说是保留的,其触摸区域扩展到导航栏之外(但是在某些情况下,附近甚至没有导航项目来窃取活动,我的观点仍然没有回复。
I'm aware that this area directly underneath the nav bar is sort of 'reserved' for the back button and other UINavigation items having a touch area that expands beyond the navigation bar (by quite a significant margin), however in some instance there isn't even a navigation item nearby to steal the event, and my views still don't respond.
奇怪的是,我是在我的UIView中调用 hitTest
方法,只是从来没有一个touchesBegan / Ended / etc。
The weird thing is that I am getting a call to the hitTest
method in my UIView, just never a touchesBegan/Ended/etc.
结果是按下按钮非常困难,如果有一个接近 UINavigatio nItem
,该项目将窃取该事件,即使在 hitTest
我将返回正确的 UIView
到系统。
The result is that it is very difficult to press the buttons and if one is anywhere near a UINavigationItem
, the item will steal the event, even though in hitTest
I am returning the correct UIView
to the system.
不幸的是我是实施者,而不是设计师所以设计变更是最后的手段。
Unfortunately I am the implementer and not the designer so a design change is a last resort.
有什么想法吗?谢谢!
推荐答案
你必须继承你的UINavigationBar并在你的CustomNavigationBar中这样做:
You have to subclass your UINavigationBar and in your CustomNavigationBar do this:
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
self.userInteractionEnabled = YES;
} else {
self.userInteractionEnabled = NO;
}
return [super hitTest:point withEvent:event];
}
有关如何创建子类UINavigationBar的信息,你可以找到在其他地方。
Info about how to subclass UINavigationBar you can find here.
这篇关于触摸未调用导航栏~8像素内的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!