如何响应UIScrollView的touchesBegan和touchesEnd消息

UIScrollView自己处理了这两个消息,但是并没有提供给UIScrollViewDelegate

因为需要支持用户点击ScrollView,从而选择其中的内容,只好从UIScrollView派生出一个新的类ClickableScrollView

重写touchesBegan和touchesEnd两个消息函数,转发出去

代码如下:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    [super touchesBegan:touches withEvent:
event];
    
if ( !self.dragging )
    {
        [[self nextResponder] touchesBegan:touches withEvent:
event];
    }
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    [super touchesEnded:touches withEvent:
event];
    
if ( !self.dragging )
    {
        [[self nextResponder] touchesEnded:touches withEvent:
event];
    }
}
原文地址:https://www.cnblogs.com/hyamw/p/2139388.html