可重用的UIScrollView 模仿UITableView
来源:互联网 发布:c语言视频下载 编辑:程序博客网 时间:2024/06/08 15:00
How to reuse/recycle custom element like uitableviewcell does?
Yes, you should restore each subview content each time, exactly as in the table view. The advantage of recycling subviews is in memory saving for view storage, and time saving for view allocation, but of course content data management is up to you.
So the standard recycling approach requires you to use a number of cells which is equal to the number of views visible at the same time on screen + the number of extra cells you may get when starting scrolling. Let's say for example you're showing 5 full views at a time (scroll view stable) and then while scrolling you will need one extra view which is partially shown, so at the end you need 5+1=6 views. This is in theory, it is recommended to use 2 more views. So you need to write two pools: one called "visibleViews" which is made of all views added as subviews to the scrollview, and another one called "availableViews" which is made of all views available for re-use. Then you create all these views and add them to the scroll view (yes: you need to adjust their frame according to their position in the scrollview, and yes, you need to setup the content again). Finally you need to track the scroll view movement by setting a delegate. The purpose of this tracking is to calculate which of the visible views is no more visible, then remove it from the visible pool and move to the usable pool. Besides the delegate must understand when a new cell is going to appear but it is still not visible, then getting it from the available pool (or alloc/init it if the pool is empty) and adding to both the visible pool and as subview of the scrollview. Of course if you want to increase performance you can place more subviews in the scroll view in order to avoid to move cells exactly when they start appearing on screen, that's why I recommended to use a couple of extra views at the sides of the scroll view.
There is a great video from WWDC 2010 (you can access it if you're a registered developer) about usage of scroll views in iOS: it explains this technique.
The Apple's PhotoScroller example code in the XCode documentation does essentially what is stated in the WWDC video and explains this technique.
code here :PhotoScroller
同事发的: https://github.com/100grams/HGPageScrollView
Infinite Scrolling – Messing with UIScrollView
WWDC 2011 Session Videos
- 可重用的UIScrollView 模仿UITableView
- UIScrollView的重用笔记
- UItableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView cell的重用
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- UITableView的重用机制
- IOS之UITableView优化-可重用机制
- iOS 瀑布流效果(模仿UITableView重用机制)
- 大神博客
- 10004 - Bicoloring(BFS)
- DICOM学习
- hdu 4396 More lumber is required (二维SPFA)
- 仅用圆规作图(链接)
- 可重用的UIScrollView 模仿UITableView
- Cocos2dx游戏开发笔记21:动手学习《Flappy Bird》之继续优化(付源码)
- 项目经历——解决ScriptManager和UpdatePanel局部刷新以及不弹出对话框问题
- JS精华总结
- sendBroadcast
- 认识接口
- 多线程提高android性能(有image相关优化内容)
- Vim启动配置
- SIGILL错误