我有一個Masterview.it有很多childviews.I使用下面的代碼來檢測觸摸的視圖,並帶前面相應的view.the代碼工作正常。但是當我添加subview到childview,它沒有工作,請幫忙嗎?(UIView *)hitTest問題?
- (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:等方法? – Eiko 2010-09-21 08:12:03
我正在移動childview圍繞ipad ..所以我用這樣的...當childview有子視圖,它沒有工作..這就是問題..(當childview沒有子視圖,它工作正常) – 2010-09-21 08:19:44
你調用的那個委託方法的代碼是什麼?你不會將hitView設置爲[super hitTest:withEvent:]之外的任何東西 - 也許這很重要。 – Eiko 2010-09-21 08:36:39