首页 > 其他 > 详细

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

时间:2014-11-01 13:17:56      阅读:817      评论:0      收藏:0      [点我收藏+]

重写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:

原文:http://www.cnblogs.com/tangbinblog/p/4066930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!