@chenbinghua
2015-10-10T12:03:32.000000Z
字数 2005
阅读 1472
iOS笔记
UIScrollView
是iOS开发中最常用的控件之一,是UITableView
和UICollectionView
的直接父类。
查看UIScrollView的头文件
@property(nonatomic) CGPoint contentOffset; // default CGPointZero
@property(nonatomic) CGSize contentSize; // default CGSizeZero
@property(nonatomic) UIEdgeInsets contentInset; // default UIEdgeInsetsZero. add additional scroll area around content
contentOffset
这个属性用来表示UIScrollView滚动的位置
(其实就是内容左上角与scrollView左上角的间距值)
contentSize
这个属性用来表示UIScrollView内容的尺寸,滚动范围(能滚多远)
contentInset
这个属性能够在UIScrollView的4周增加额外的滚动区域,一般用来避免scrollView的内容被其他控件挡住
@property(nonatomic) BOOL bounces;
// 设置UIScrollView是否需要弹簧效果
@property(nonatomic,getter=isScrollEnabled) BOOL scrollEnabled;
// 设置UIScrollView是否能滚动
@property(nonatomic) BOOL showsHorizontalScrollIndicator;
// 是否显示水平滚动条
@property(nonatomic) BOOL showsVerticalScrollIndicator;
// 是否显示垂直滚动条
打开UIScrollViewDelegate
的头文件,可以看到一堆代理方法
常用的代理方法有
- (void)scrollViewDidScroll:(UIScrollView *)scrollView; // any offset changes
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
// 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; // called on finger up as we are moving
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating
内容缩放
分页
self.automaticallyAdjustsScrollViewInsets = NO;