您可以子类UITableView并重写ToucheSended:WithEvent:。当用户举起手指时,这个方法会受到攻击。由于您可能不想在用户点击屏幕时禁用用户交互,因此您可以捕获初始触摸起点和触摸终点。从这两个方面,您可以比较y的增量,以确定在禁用用户交互之前希望用户移动多少。这里有一些代码可以帮助您一路前进。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
touchStartPoint = [touch locationInView:self];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchEndPoint = [touch locationInView:self];
CGFloat deltaY = touchStartPoint.y - touchEndPoint.y;
if (fabsf(deltaY) >= kMinimumYMoved) {
self.userInteractionEnabled = NO;
}
}