IOS--常用控件--UIScrollView
2014-09-26 17:35 doudo 阅读(277) 评论(0) 编辑 收藏 举报scrollView每次停止时执行的代理方法:
一、手动导致scrollView的滑动时:
1.手滑一下scrollView,然后松开,scrollView自己慢慢停止,执行的方法:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//OK,真正停止了,do something
}
2.手一直在scrollView上按着,受控制着scrollView最后停止,执行的方法:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(!decelerate)
{ //OK,真正停止了,do something}
}
二、通过setContentOffset导致scrollView滑动:
停止时会执行的方法:(前提是"(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated"触发时,animated为YES.为no时,其实也没必要用代理方法了,直接set后就能处理)
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{}
综上可得,想要在每次scrollView滑动结束后执行某方法,
1.如果myScrollView.pagingEnabled=YES, 用
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//do something
}
2.如果.pagingEnabled=NO,则需要用两个
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(!decelerate)
{ //OK,真正停止了,do something}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//OK,真正停止了,do something
}