ios 滚动视图响应touchesBegin,touchesEnd等方法

能够滚动的控件都不会响应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];
    }
}

posted @ 2014-07-11 17:07  shidaying  阅读(334)  评论(0编辑  收藏  举报