码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-11-01 13:20:22      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   for   sp   div   log   

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

标签:style   blog   http   color   ar   for   sp   div   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!