首页 > 技术文章 > ios 滚动视图响应touchesBegin,touchesEnd等方法

shidaying 2014-07-11 17:07 原文

能够滚动的控件都不会响应touchesBegin,touchesEnd等方法,这就需要对这个类进行封装

以UITextView为例

1,创建CustomTextView类,继承与UITextView

2,在CustomTextView.m文件中重写touchesBegin,touchesEnd等方法

3,代码如下:

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

推荐阅读