我尝试过的一件事是禁用识别器,但是那样它就无法滚动直到下一个触摸事件。所以我需要它立即传递事件。
我尝试过的另一件事是自己滚动,但是这样你会错过停止触摸后的持续速度。
以下是一些代码:
//In the viewdidload method
UIPanGestureRecognizer *slideRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(sliding:)];
[myTable addGestureRecognizer:slideRecognizer];
-(void)sliding:(UIPanGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
CGPoint translation = [recognizer translationInView:favoritesTable];
if (sqrt(translation.x*translation.x)/sqrt(translation.y*translation.y)>1) {
horizontalScrolling = YES; //BOOL declared in the header file
NSLog(@"horizontal");
//And some code to determine what cell is being scrolled:
CGPoint slideLocation = [recognizer locationInView:myTable];
slidingCell = [myTable indexPathForRowAtPoint:slideLocation];
if (slidingCell.row == 0) {
slidingCell = nil;
}
}
else
{
NSLog(@"cancel");
}
if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled)
{
horizontalScrolling = NO;
}
if (horizontalScrolling)
{
//Perform some code
}
else
{
//Maybe pass the touch from here; It's panning vertically
}
}
那么,有关于如何传递触摸的建议吗?
补充:我也考虑过子类化tableview的手势识别方法,首先检查它是否是水平的;然而,那么我需要原始代码,我想...不知道苹果公司会不会有问题。 另外:我没有子类化UITableView(控制器),只是单元格。这段代码在持有表格的视图控制器中 ;)