做跑马灯组件时,需要在UIView视图中添加子视图UIScrollview,以便可以进行多个内容的向上滚动显示,同时也在UIView中添加了UITouch事件,但是UITouch点击却没有响应。
怎么解决呢?
出现问题原因:UIScrollView自身就有手势响应的事件,从响应链原理来看,触发响应后,手势事件被UISCrollView拦截了,不会再往下传递给UIScrollView的父视图,即UIView,所以不会响应UIView中的UITouch事件。
解决方案:
创建一个UIScrollView的category,重写UITouch方法。
如:UIScrollView+UITouch.h、UIScrollView+UITouch.m,并在UIScrollView+UITouch.m文件中重写UITouch方法
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// [[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// [[self nextResponder] touchesCancelled:touches withEvent:event];
[super touchesCancelled:touches withEvent:event];
}
- (v