您好,我正在尝试转发从 UITableView 前面的 UIView 收到的触摸。但这样做我不能再让桌子滚动了(see here https://stackoverflow.com/questions/3417808/uitableview-custom-gestures-make-it-scrolling-no-more).
所以现在我正在尝试以编程方式使表格视图滚动,我正在查看setContentOffset:animated:
and scrollRectToVisible:animated:
只有第一个才能成功。
这是我在 UITableView 子类中的代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"BEGTB");
//previousXPan = 0.0;
UITouch * touch = [touches anyObject];
CGPoint tPoint = [touch locationInView:self];
previousYPan = tPoint.y;
[super touchesBegan:touches withEvent:event];
//
//[super touchesShouldBegin:touches withEvent:event inContentView:self];
//[[self nextResponder] touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch * touch = [touches anyObject];
CGPoint tPoint = [touch locationInView:self];
NSLog(@"MOVTB");
NSLog(@"BOUNDZ %f, %f, %f, %f", self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.height, self.bounds.size.width);
NSLog(@"CONTENT SIZE %f, %f", self.contentSize.height, self.contentSize.width);
CGRect rc = [self bounds];
NSLog(@"%f %f", rc.size.height, rc.size.width);
CGRect newRect = CGRectMake(rc.origin.x, rc.origin.y + self.contentSize.height, self.contentSize.width, fabs(tPoint.y - previousYPan));
NSLog(@"BOND RECT %f, %f, %f, %f", rc.origin.x, rc.origin.y, rc.size.height, rc.size.width);
NSLog(@"NEW RECT %f, %f, %f, %f", newRect.origin.x, newRect.origin.y, newRect.size.height, newRect.size.width);
//[self scrollRectToVisible:newRect animated:YES];
NSLog(@"Content OFFSET %f",tPoint.y - previousYPan);
[self setContentOffset:CGPointMake(rc.origin.x,(tPoint.y - previousYPan) *2.0 )animated:YES];
previousYPan = tPoint.y;
//[super touchesMoved:touches withEvent:event];
//[[self nextResponder] touchesMoved:touches withEvent:event];
}
但结果确实很滞后且有问题。还有更好的主意吗?