首页 > 代码库 > UITableView/UIScrollView 不能响应TouchBegin 的处理 及窥见 hitTest:withEvent:

UITableView/UIScrollView 不能响应TouchBegin 的处理 及窥见 hitTest:withEvent:

重写touchBegin 方法是不行的,在UITableView/UIScrollView

解决方案 重写hitTest:withEvent:  在他们的子类中

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {        static UIEvent *e = nil;        if (e != nil && e == event) {        e = nil;        return [super hitTest:point withEvent:event];    }        e = event;        if (event.type == UIEventTypeTouches) {        NSSet *touches = [event touchesForView:self];        UITouch *touch = [touches anyObject];        if (touch.phase == UITouchPhaseBegan) {            NSLog(@"Touches began");        }else if(touch.phase == UITouchPhaseEnded){            NSLog(@"Touches Ended");        }else if(touch.phase == UITouchPhaseCancelled){            NSLog(@"Touches Cancelled");        }else if (touch.phase == UITouchPhaseMoved){            NSLog(@"Touches Moved");        }    }    return [super hitTest:point withEvent:event];}

关于hitTest:withEvent: 

参见:http://www.cnblogs.com/klaus/archive/2013/04/22/3036692.html

UITableView/UIScrollView 不能响应TouchBegin 的处理 及窥见 hitTest:withEvent: