开发者

How to smoothly scroll through 600ish uilabels on a big uiscrollview (iphone)

I have a bit gantt chart that i want to be visible on an iphone.

It is 7200 x 1800px large, and consists of ~600 bars, each of which is a UILabel.

It is to look like this:

How to smoothly scroll through 600ish uilabels on a big uiscrollview (iphone)

Now i've gotten it to work. And at ~100 bars, i can make it ru开发者_JAVA技巧n quite smoothly by simply adding them all to the scroll view. However, with the full 600 (or more eventually) it simply crashes when i instantiate all those uilabels and add them all to the scroll view as subviews.

So what i've done is made it create only the uilabels for the currently visible rows, and as the user scrolls up and down it removes the invisible uilabels and adds the newly visible ones.

However, this jerks quite noticeably as you scroll vertically as it crosses each row boundary, and has to render another row and remove the old row.

Does anyone have any suggestions to solve this? Any ideas what is the slow part? Instantiating the uilabels, or adding them as subviews, or anything?

All help will be greatly appreciated.


Apple has some really good demo code that shows how to do this. Check out TiledScrollView.m especially the layoutSubviews method.

Other things you might consider:

  • If you labels are quite long horizontally you may need to break them into smaller chunks. Quite long in this context is wider than the screen.

  • Make sure your UILabels are opaque. Scrolling things that require compositing adds extra overhead which may account for some of your issues.

  • Looking at your screen shot the row and column headers are not opaque and are using alphas. Whereas this is a nice effect it may be worth temporarily making them opaque too just to see if this is contributing to your problems. I don't think this is contributing too much to your problems; the area being composited is quite small.


Just a thought, but could the issue be that even though you are caching and reusing the labels, is the scroll view still retaining them, so even though you may only have a few labels, each is being retained hundreds of times. If this is so then I would think that the scroll view is still effectively trying to manage those hundreds of rows.

So as @Nathon S asked - are you moving them? i.e. building a finite set of labels and just moving them around on the scroll view to match the viewing area. If you are hiding and re-adding to the scroll view then I would suspect a massive set of retains being the slow down. I would think that with a moving label design, you would not need to do any hides and adds after the the initial display. Which should make it very fast and lightweight.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜