日度归档:2016年5月28日

IOS控件-UIScrollView简介(一)


一、UIScrollView控件简介


当IOS屏幕内容不足以展示所有内容时,此时我们需要使用UIScrollView控件来控制显示屏幕以外的内容。


二、UIScrollView使用

当将需要显示的内容添加到UIScrollView控件中,通过设置contentSize属性,我们就可以知道整个UIScrollView的内容尺寸,然后UIScrollView可以在内容范围内进行滚动

三、UIScrollView属性

@property(nonatomic)CGPointcontentOffset; //UIScrollView滚动位置
@property(nonatomic)CGSizecontentSize; //UIScrollView内容尺寸,控制滚动范围
@property(nonatomic)UIEdgeInsetscontentInset; //增加额外滚动区域(常用于)

@property(nonatomic) BOOL bounces; // 是否有缩放弹动效果

@property(nonatomic,getter=isScrollEnabled)BOOLscrollEnabled; // UIScrollView是否能滚动

@property(nonatomic) BOOL showsHorizontalScrollIndicator; //UIScrollView 是否显⽰⽔水平滚动条

@property(nonatomic) BOOL showsVerticalScrollIndicator; //是否UIScrollView 是否显⽰垂直滚动条


四、UIScrollView方法

– (void)scrollViewDidScroll:(UIScrollView *)scrollView; //任何UIScrollView的内容尺寸变化都会触发 // any offset changes
– (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // 任何缩放的变化

// called on start of dragging (may require some time and or distance to move)
– (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; //当UIScrollView开始滚动时触发
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
– (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
– (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

– (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; // 当开始移动时执行方法
– (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // 当滚动操作停止后

– (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; //

– (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; // 当进行UIScrollView缩放操作

– (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2); // 开始缩放时执行
– (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale; // 缩放结束前执行

– (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; // 当快要滚动到顶端的时候,返回yes,执行此方法
– (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView; // 当UIScrollView滚动到top后执行

相关阅读:
IOS控件-UIScrollView简介(二)