开发者

Displaying one graph per day, home screen style

I'm working on an app that can display a graph with some data, one every day. I'll call this "dayGrap开发者_如何学编程h".

I'd like to build an interface similar to the iPhone home screen, aka pageControl, with one dayGraph per page. (but i don't need the small dots!)

I tried with the standard pageControl example from Apple, and it's working, but only with a small number of pages. I need to display even 100 possible dayGraph, if the user wants, but the pageControl is going crazy when the page number exceed 50.

I know that the photo app is doing a similar thing, and it can work with many photos.

My question is: How can i do that? Is there any "Apple way" of doing it, or i should begin to make my own method for swapping the dayGraphs?

Thank you very much!


If your goal is to enable swipe-based paging, the view you want to use is a UIScrollView. Set its pagingEnabled property to YES. Then add each graph as a subview of your UIScrollView, setting the frame of each graph to position each one on its own page extending beyond the bounds of your UIScrollView to the right. Finally, update the contentSize property of your UIScrollView to encompass all of your pages.

Now the user can swipe left and right to flip between the pages of your scroll view.

Note: If you add 50+ subviews to your scrollview, it's likely that you'll run into memory problems. To avoid this, you'll probably want just keep subviews loaded for the current page, plus the adjacent pages to the right and left. Set a delegate on your UIScrollView to an object that implements scrollViewDidEndDecelerating:. In that method, remove any subviews that aren't on the current or adjacent pages, and make sure each adjacent page has its subview loaded. That way you'll never have more than 3 pages of content in memory at one time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜