在ios设计的过程中,对于UIScrollView这个控件对于开发者而言都不会陌生,在处理UI界面的时候我们经常会用到UIScrollView,既然用到了UIScrollView,那么UIScrollView的几个代理方法就无法避免的被使用了。本文并不介绍UIScrollView的相关属性,就介绍几个代理方法。
/ 此方法在scrollView滑动时会被调用多次,只要scrollView.contentOffset发生改变就会被调用 /
(void)scrollViewDidScroll:(UIScrollView *)scrollView { NSLog(@"scrollViewDidScroll"); }
/* 再一次拖动滑动中最后被调用,在
(void)scrollViewDidScroll:(UIScrollView )scrollView; 之后 /
(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { NSLog(@"scrollViewDidEndDecelerating"); }
/ 此方法在拖动结束后将要开始减速时被调用 /
(void)scrollViewDidEndDragging:(UIScrollView )scrollView willDecelerate:(BOOL)decelerate { NSLog(@"scrollViewDidEndDragging:(UIScrollView )scrollView willDecelerate"); }
/*此方法在手动滑动时不会调用,只有在
(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
(void)scrollRectToVisible:(CGRect) animated:(BOOL)animated; 调用后才调用 */
(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { NSLog(@"scrollViewDidEndScrollingAnimation"); }
/ 此方法在开始减速时被调用,再一次拖动滑动中最先被调用 /
(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { NSLog(@"scrollViewWillBeginDecelerating"); }
/ 当scale发生改变时,调用此方法,此方法会被调用多次 /
(void)scrollViewDidZoom:(UIScrollView *)scrollView { NSLog(@"scrollViewDidZoom"); }
//滚动到顶部( (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
return YES;返回yes时才调用滚动到顶部的代理
}/
(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView { NSLog(@"scrollViewDidScrollToTop"); }
/ 此方法在拖动开始时被调用,一次拖动抵用一次,未发生触控不会被调用 /
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { NSLog(@"scrollViewWillBeginDragging"); }
/ 此方法在scale开始时被调用,一次scale调用一次 /
(void)scrollViewWillBeginZooming:(UIScrollView )scrollView withView:(UIView )view { NSLog(@"scrollViewWillBeginZooming"); }
/ 特别注意这个方法,此方法可以获取Velocity可以用于判断滑动方向,tarContentOffset可以用于判断是否会已经滑动翻页
(void)scrollViewWillEndDragging:(UIScrollView )scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint )targetContentOffset { NSLog(@"targetContentOffset"); }
/ zoom之后会被调用,可以用atScale得到zoom值从而进行进一步处理 /
(void)scrollViewDidEndZooming:(UIScrollView )scrollView withView:(UIView )view atScale:(CGFloat)scale { NSLog(@"atScale"); }
//此方法设置可以scale的view
(nullable UIView )viewForZoomingInScrollView:(UIScrollView )scrollView { if (scrollView == self.myScrollView2) { NSLog(@"hahah"); return self.Views[0]; } return nil; }
网友评论