UITabBar / UIToolBar重叠问题(iphone sdk) [英] UITabBar / UIToolBar overlap problem (iphone sdk)

查看:107
本文介绍了UITabBar / UIToolBar重叠问题(iphone sdk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITabBar上方的另一个视图中有一个自定义按钮。看起来像UITTabBar上面有一个隐藏的打击区域,这阻止我击中另一个视图中我的自定义按钮的下半部分。按钮子视图位于所有其他视图之上,包括自定义UITabBar。



使用UICatalog示例代码在模拟器中很容易注意到这种效果。转到工具栏部分。将鼠标光标放置在底部工具栏项目上方约5-10个像素处,然后点击查看可以触发按钮上方的触摸事件。



我需要弄清楚如何将这个命中区域限制在uitoolbar或uitabbar本身的边界,而不是让iPhone做任何类型的命中无障碍魔法。 p>

我想我已经用尽所有选项:\我认为clipsToBounds(在UITabBar上)会做的伎俩,但显然不是。



此外,我完全在代码中这样做,所以没有界面生成器...

解决方案

谁绊倒这个问题,我有一个解决方案,虽然它落入肮脏的黑客领土,可能会与更新的(超过3.0)iPhone操作系统版本... 使用在你的危险!



我创建了一个带有 hitTest:withEvent:实现的UITabBar类别,并且注意到当我设置断点这个方法的主体,提供的CGPoint结构中的x,y值是奇怪的 - 当触摸到〜15px左右的标签栏的值看起来像(x = 23.482749,y = 12.938475),而如果你在标签栏内触摸值可以很好地舍入到最接近的整数,例如(x = 23,y = 12)。



现在,由于某种原因,我期望在标签栏上方〜15px命中区对于y轴(这就是为什么我开始沿着这条路径在第一个地方),但唉,没有。您可以在两个不同的地方触摸并获得类似的坐标,例如上面的示例。



所以,我的解决方案:我依靠触摸标签栏本身总是具有y轴的整数四舍五入值,否则我假设它在标签栏上方的重叠区域。



代码:

  @implementation UITabBar(Me)

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if([[NSString stringWithFormat:@%。6f,point.y] hasSuffix:@。000000])
{
return [super hitTest:point withEvent:event];
}
else
{
return nil;
}
}

@end


I have a custom button in another view directly above my UITabBar. It seems like there's a hidden "hit area" above the UITTabBar that is preventing me from hitting the bottom half of my custom button in another view. The button subview is on top of all other views including the custom UITabBar.

It's really easy to notice this effect in the simulator using the UICatalog sample code. Head to the toolbar section. Position your mouse cursor about 5-10 pixels above the tool bar items on the bottom and click to see that you can trigger the touch event way above the button.

I need to figure out how to restrict this hit area to the bounds of the uitoolbar or uitabbar itself and not let the iPhone do any sort of hit accessibility magic.

I think I've exhausted all options :\ I thought clipsToBounds (on the UITabBar) would do the trick, but apparently not.

Also I'm doing this completely in code, so no Interface Builder...

解决方案

For anyone who stumbles across this question, I have a solution for this, although it falls well into "dirty hack" territory, and may break with newer (than 3.0) iPhone OS releases... use at your peril!

I created a UITabBar category with a hitTest:withEvent: implementation, and noticed when I set a breakpoint in the body of this method that the x,y values in the supplied CGPoint struct were rather odd - when touching in the ~15px or so ABOVE the tab bar the values look something like (x=23.482749, y=12.938475), whereas if you touch within the tab bar the values were nicely rounded to the nearest integer, e.g. (x=23, y=12).

Now, for some reason I was expecting the touches in the ~15px "hit zone" above the tab bar to be negative for the y axis (which is why I started down this path in the first place), but alas, no. You can touch in two different places and get similar coordinates, such as in the example above.

So, my "solution": I'm relying on a touch in the tab bar itself always having an integer-rounded value for the y axis, otherwise I'm assuming it's in the overlap zone above the tab bar. I tested this for quite a while, and it seems to consistently behave this way.

The code:

@implementation UITabBar (Me)

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 
{
  if ([[NSString stringWithFormat:@"%.6f", point.y] hasSuffix:@".000000"])
  {
    return [super hitTest:point withEvent:event];
  }
  else
  {
    return nil;
  }
}

@end

这篇关于UITabBar / UIToolBar重叠问题(iphone sdk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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