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.
On this page
"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(@"向下");
}
}