UIScrollView的正确使用方法

scrollView 的ContentSize一定要比 它的frame大,否则无法响应滑动的事件

 

http://www.iphonedevsdk.com/forum/iphone-sdk-development/102099-uiscrollview-tabbar-application.html

 

Let's say you put a scroll view on the screen, and it is 100x100. If the content size is also 100x100, why would it scroll? You can already see everything, there is no reason to scroll.

Now make them each 200x200. Why would it scroll?

300x300. Why would it scroll?

400x400. Why would it scroll? Ah-ha! Now this view is too big to fit on the screen. So what? You said the view is 400x400, you said the content size is 400x400, so why would it scroll? If you take the 100x100 case, and slide it over so that it is half off the screen, why would it scroll? Just because it is partially off screen now? It doesn't work like that.

So if the view is 100x100, and the content size is 200x200, now you can scroll. You could be looking at the upper left corner, the upper right corner, lower left, lower right, somewhere in the middle, etc. 200x200 does not fit inside 100x100, therefore it can scroll. So the content size has to be larger than the frame, otherwise there is no reason to scroll.

posted @ 2012-05-10 15:32  worldworld  阅读(244)  评论(0编辑  收藏  举报