在UIScrollView中查找滚动方向?
我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"); }}
但是当我移动时,这种方法有时根本不会被调用。你怎么看?
幕布斯6054654
缥缈止盈
暮色呼如