有时候会遇到两个scrollview在一起嵌套使用,滑动冲突是必须要解决的
如:在一个scrollview上面放置另一个scrollview 通过监听手指点击的位置来判断点击的是哪一个scrollview来进行处理
首先自定义一个scrollview在里面重载以下方法
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
// 获取一个UITouch
UITouch *touch = [touches anyObject];
// 获取当前的位置
CGPoint current = [touch locationInView:self];
CGFloat y = 280;
if (current.y >= y+ 10) {
//在地图上
NSLog(@"滚动地图");
return YES;
} else {
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}
}
touchesShouldCancelInContentView从字面理解大概意思为 应该取消当前视图的触摸事件
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
if ([view isKindOfClass:NSClassFromString(@"TapDetectingView")]) {
//在地图上返回NO
return NO;
} else {
return [super touchesShouldCancelInContentView:view];
}
}
self.delaysContentTouches = NO;
当手指放到UIScrollview上时,uiscrollview会等待一个时间段才去响应触摸事件,这个属性关闭后无论手指移动的多么快都可以直接响应事件