【发布时间】:2011-04-15 01:49:47
【问题描述】:
我有一个 Masterview。它有很多子视图。我正在使用以下代码来检测被触摸的视图并将相应的视图放在前面。代码工作正常。但是当我将子视图添加到子视图时,它不起作用,有什么帮助吗?
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
{
self.hitView = nil;
self.hitView = [super hitTest:point withEvent:event];
int x = self.hitView.frame.origin.x;
int y = self.hitView.frame.origin.y;
NSLog(@"x = %d",x);
NSLog(@"y = %d",y);
if ([self.viewDelegate respondsToSelector:
@selector(view:hitTest:withEvent:hitView:)])
{
return [self.viewDelegate view:self hitTest:point
withEvent:event hitView:hitView];
}
else
{
[self bringSubviewToFront:self.hitView];
return hitView;
}
}
【问题讨论】:
-
有什么原因不能直接在子视图中使用 touchesBegan: etc. 方法吗?
-
我正在 ipad 区域周围移动 childview..所以我这样使用...当 childview 有子视图时,它不起作用..这就是问题..(当 childview 有没有子视图,它工作正常)
-
您调用的委托方法的代码是什么?除了 [super hitTest:withEvent:] 之外,您没有将 hitView 设置为任何其他值 - 也许这很重要。
-
对于这种命中测试,我认为您应该使用 iOS 3.2 (iPad) 中的超棒功能:developer.apple.com/library/ios/#documentation/uikit/reference/… 它工作得非常好。在我看来,使用 touchesBegan 已经没有用了。新的 UIGestureRecognizer 类确实使触摸事件变得容易。这是developer.apple.com/library/ios/#documentation/uikit/reference/… 的链接。看看吧。
标签: iphone ipad uiview uiviewcontroller