简体   繁体   English

使用大量子视图优化UIScrollView

[英]Optimizing a UIScrollView with a lot of subviews

I have a UIScrollView that I am using to simulate a UITableView like interaction because rows are a bit more complex than what UITableView has to offer. 我有一个UIScrollView,我用来模拟UITableView之类的交互,因为行比UITableView提供的要复杂一些。 I have 4 UILables a UIImageView and a UIButton for every row. 我有4个UILables UIImageView和每行UIButton。 The end result is a lot of subviews. 最终结果是很多子视图。

Even with only 10 rows,the scroll view that looks fine in the simulator but has a fairly low frame rate on the iPhone 4. This is a resource consumption issue for sure. 即使只有10行,滚动视图在模拟器中看起来很好但在iPhone 4上具有相当低的帧速率。这肯定是资源消耗问题。

Is there a way to optimize the redraw durring scrolling like double buffering? 有没有办法优化重绘滚动像双缓冲?

If not is there another way to get customizable UITableview functionality? 如果没有,是否有其他方法可以获得可自定义的UITableview功能?

thanks 谢谢

Does every View have 4xUILabels, a UIImageView and a UIButton? 每个View都有4xUILabels,UIImageView和UIButton吗?

I would create a nib file with a custom UITableViewCell (You can make those as complex as you want), then you can reuse the cells to help with your performance. 我将创建一个带有自定义UITableViewCell的nib文件(您可以根据需要制作那些复杂的),然后您可以重复使用单元格来帮助您提高性能。

Information on how to do this is here: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1 有关如何执行此操作的信息,请访问: http//developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

I think you probably want to create a custom subclass of a UITableViewCell as the UITableView will handle all the redrawing for you. 我想您可能想要创建一个UITableViewCell的自定义子类,因为UITableView将为您处理所有重绘。 In a custom UITableViewCell you can add as many subviews as you like. 在自定义UITableViewCell中,您可以添加任意数量的子视图。

Take a look at http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html . 请访问http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

UITableViews are subclasses of UIScrollView (or at least conform to their behavior), but you really want to let the iPhone handle the selective drawing/cell reuse for you that the UITableView provides. UITableViews是UIScrollView的子类(或者至少符合它们的行为),但是你真的想让iPhone为你提供UITableView提供的选择性绘图/单元重用。

You should use UITableView if it does everything you need. 如果它能够满足您的所有需求,您应该使用UITableView

However if your tableview cells are really complicated, or you want to enable paging on the scrollview, you should take a look at the PageContol sample code that Apple provides. 但是,如果您的tableview单元格非常复杂,或者您想在scrollview上启用分页,则应该查看Apple提供的PageContol示例代码。 In a nutshell, you watch for movement in scrollViewDidScroll: and load new "pages" just before they become visible. 简而言之,您在scrollViewDidScroll:观察移动scrollViewDidScroll:并在它们变得可见之前加载新的“页面”。 This method works very well in practice for arbitrarily long lists of pages. 对于任意长的页面列表,此方法在实践中非常有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM