我有一个只允许水平滚动的UIScrollView
,我想知道用户滚动的方向(左或右)。我的做法是对UIScrollView
进行子类化,并重写touchesMoved
方法:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
float now = [touch locationInView:self].x;
float before = [touch previousLocationInView:self].x;
NSLog(@"%f %f", before, now);
if (now > before){
right = NO;
NSLog(@"LEFT");
}
else{
right = YES;
NSLog(@"RIGHT");
}
}
但是当我移动时,这种方法有时候根本不会被调用。你觉得怎么办?