【发布时间】:2011-08-16 04:57:03
【问题描述】:
我有一个简单的 - 微不足道的 - UIView 父/子层次结构。一位家长(UIView)。一个孩子(UIButton)。父母的界限比它的孩子的界限小,因此孩子的一部分延伸到其父母的边界框之外。
问题是:父 bbox 之外的子部分不接收到触摸。只有在父母的 bbox 内点击才允许子按钮接收触摸。
有人可以建议修复/解决方法吗?
更新
对于那些关注这个问题的人,这是我根据@Bastian 最优秀的答案实施的解决方案:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
BOOL isInside = [super pointInside:point withEvent:event];
// identify the button view subclass
UIButton *b = (UIButton *)[self viewWithTag:3232];
CGPoint inButtonSpace = [self convertPoint:point toView:b];
BOOL isInsideButton = [b pointInside:inButtonSpace withEvent:nil];
if (isInsideButton) {
return isInsideButton;
} // if (YES == isInsideButton)
return isInside;
}
【问题讨论】:
-
只是想指出您的
hitTest:withEvent:覆盖实际上并没有改变任何东西,因为它只是调用超级的实现。所以没必要。 -
@dugla:请从问题中删除您的解决方案并将其作为答案发布。
-
在哪个子类中覆盖
pointInside:,子视图?