1. 程式人生 > >UIScrollView判斷滾動方向

UIScrollView判斷滾動方向

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    static float newY = 0;

    newY = scrollView.contentOffset.y;
    if (newY != _oldY) {
        if (newY > _oldY && (newY - _oldY) > 100) {
            NSLog(@"Down");
            _oldY = newY;
        } else if (newY < _oldY && (_oldY - newY) > 100) {

            NSLog(@"Up");
            _oldY = newY;
        }
    }
}