2.23 Creating Scrollable Content with UIScrollView

来源:互联网 发布:最优化导论中文版 编辑:程序博客网 时间:2024/04/27 10:21

他是一个UIView,你可以像对待UIView一样对待它。
你需要特别注意的是他的contentSize 属性,如果没设置好,他将不会滚屏(contentSize应该大于UIScrollView 的size)。

UIScrollViewDelegate  滚动代理

scrollViewDidScroll:当被滚动了就会触发,也就是在滚动过程中会一直触发的
scrollViewWillBeginDecelerating:开始减速,在手机离开屏幕时触发
scrollViewDidEndDecelerating: 结束减速,滚动停止时触发,结束滚屏
scrollViewDidEndDragging:willDecelerate:结束拖拽,这个方法有些像结束滚屏。区别:滚屏是那种,手指快速划一下,然后让屏幕滚一会的那种;拖拽就是把显示的内容拖过来一点,没有让屏幕滚的。

试了几个消息代理,做了一次滚屏操作,触发顺序如下

2013-11-11 10:08:45.478 SingleViewWithOutStoryboards[437:c07] will Begin Dragging
2013-11-11 10:08:45.481 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.494 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.512 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.517 SingleViewWithOutStoryboards[437:c07] Will End Dragging
2013-11-11 10:08:45.517 SingleViewWithOutStoryboards[437:c07] Did End Dragging
2013-11-11 10:08:45.518 SingleViewWithOutStoryboards[437:c07] Will Begin Decelerating
2013-11-11 10:08:45.535 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.552 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.569 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.586 SingleViewWithOutStoryboards[437:c07] Did Scroll
2013-11-11 10:08:45.602 SingleViewWithOutStoryboards[437:c07] Did Scroll
......
2013-11-11 10:08:47.319 SingleViewWithOutStoryboards[437:c07] Did End Decelerating

不过有时在找联系人时,会用力一划,滚到快到那个联系人了,赶紧按住。试了一下,结果如下
2013-11-11 10:27:19.533 SingleViewWithOutStoryboards[481:c07] will Begin Dragging
2013-11-11 10:27:19.534 SingleViewWithOutStoryboards[481:c07] Did Scroll
2013-11-11 10:27:19.541 SingleViewWithOutStoryboards[481:c07] Will End Dragging
2013-11-11 10:27:19.542 SingleViewWithOutStoryboards[481:c07] Did End Dragging
2013-11-11 10:27:19.542 SingleViewWithOutStoryboards[481:c07] Will Begin Decelerating
2013-11-11 10:27:19.560 SingleViewWithOutStoryboards[481:c07] Did Scroll
2013-11-11 10:27:19.577 SingleViewWithOutStoryboards[481:c07] Did Scroll
2013-11-11 10:27:19.593 SingleViewWithOutStoryboards[481:c07] Did Scroll
......
2013-11-11 10:27:19.902 SingleViewWithOutStoryboards[481:c07] will Begin Dragging
2013-11-11 10:27:20.830 SingleViewWithOutStoryboards[481:c07] Will End Dragging
2013-11-11 10:27:20.831 SingleViewWithOutStoryboards[481:c07] Did End Dragging
2013-11-11 10:27:20.844 SingleViewWithOutStoryboards[481:c07] Did End Decelerating

滚动条样式
indicatorStyle

typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {
    UIScrollViewIndicatorStyleDefault,     // black with white border. good against any background
    UIScrollViewIndicatorStyleBlack,       // black only. smaller. good against a white background
    UIScrollViewIndicatorStyleWhite        // white only. smaller. good against a black background
};


翻页
pagingEnabled boolean
我们在浏览照片的时候,会翻页一张一张的看,pagingEnabled 就是用来指定要实现这样的效果。

 

 

 

 

 

 

 

 

 

 

原创粉丝点击