【发布时间】:2014-08-12 03:55:57
【问题描述】:
我有一个包含另一个视图的 UIView,它自身包含一个 UIButton。问题是 MENUVIEW 真的很窄,所以我的 DROPDOWN 延伸到它上面,当它发生并且用户点击 (K) 时没有任何反应。我知道我必须覆盖 HitTest: 和 pointInside: 但我不确定在哪个视图中以及如何?
我是否覆盖 A、B 或 K 中的 hitTest?并且点在 A、B 或 K 内?
例子:
(A) is MENUVIEW, the parent of all views
(B) is DROPDOWN, a subview of MENUVIEW
(K) is UIBUTTON, a subview of DROPDOWN
图表:
+---------------+
|A |
| |
| |
| |
|+--------------|----------+
||B | +K---+ |
|| | +----+ |
|+--------------|----------+
+---------------+
更新:
这是我放入的代码,但它不起作用。使用下面的代码,我单击 B,然后 B 将打开并显示 K,但 K 仍然不可单击。 Point inside 没有被调用 (A)?
#pragma mark - Clickable Area()
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGFloat radius = 200.0;
CGRect frame = CGRectMake(self.dropDownMenu.frame.origin.x, self.dropDownMenu.frame.origin.y + 50,
200,
174); <-- this B's frame area minus the part of B inside A (i.e. just K and the part of B outside A)
if (CGRectContainsPoint(frame, point)) {
return self.dropDownMenu;
} else {
return [super hitTest:point withEvent:event];
}
return nil;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (CGRectContainsPoint(self.bounds, point)) {
return YES;
}
return NO;
}
@end
【问题讨论】:
-
请提供一些源代码。另外,这里有一些可能有用也可能没用的东西:检查
userInteractionEnabled。 -
还有,你为什么要和 hitTest 和朋友们搞混?
标签: ios objective-c hittest