UIKit & graphicsHistorical technical note

A small iOS scrolling demo inspired by Zhe800

Uses a Zhe800-style scrolling interaction to demonstrate recording contentOffset when dragging begins and comparing offsets in scroll callbacks to determine direction. An example project shows how the interface elements respond together.

The original does not clearly identify an author. Retained as a historical article.

English translation of the Chinese original, translated on . The article body uses automated translation; app descriptions, historical reading notes and video subtitles receive separate editorial checks. Original publication dates, attribution, code and version notes are retained.

"The beginning is the most important part of the work." Plato

– Core code –

-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{

    //使用的时候用全局变量
    CGFloat lastContentOffset = scrollView.contentOffset.y;
}


-( void )scrollViewDidScroll:( UIScrollView *)scrollView {
    
    if (scrollView.contentOffset.y < lastContentOffset )
    {

        //向上
        NSLog(@"向上");

    } else if (scrollView. contentOffset.y >lastContentOffset ){
        //向下
        NSLog(@"向下");
    }
}

Click here → download the demo

(LBMoviesPossession)