1. 程式人生 > >如何判斷UIScrollView滑動方向

如何判斷UIScrollView滑動方向

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //Selected index's color changed.
    static float newx = 0;
    static float oldIx = 0;
    newx= scrollView.contentOffset.x ;
    if (newx != oldx ) {
        //Left-YES,Right-NO
        if (newx > oldx) {
            self.scrollLeftOrRight = NO;
        }else if(newIndex < oldIndex){

            self.scrollLeftOrRight = YES;
        }
        oldx = newx;
    }
}