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