开发者

Setting correct sizes when using UIScrollView and setContentSize

I simply just want to have more controls than I can fit on the normal iPhone screen. Take for example viewing someone's contact information in the Contacts app.

It appears that I should use a UIScrollView to implement this.

Lets say I need about 800 pixels for this. So in my NIB, I set the View of the ScrollView to have a height of 800. I then add my controls under the Scroll View.

I make my connection, and then in the viewDidLoad, I do the usual:

[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 800)];

If I build and run at this state, it wont scroll. So looking around online, people say that you have to set this to be larger than the UIScrollView.

I can't seem to find information on how to actually calculate what that 800 should be in the setContentSize. Is it just guessing until it looks right? If I set it to 801, I never see everything at the bottom of my Scroll View, and if I set it to 1000 I can see the bottom, but it doesn't really end at the bottom.

I just want that if the user scrolls down, it ends at the bottom correctly.

How is this calculated? Or am I missing something? This seems like a rather common use but haven't 开发者_如何学编程found code examples that simulate this simple example.


Scrollview provides a perspective onto a bigger canvas by showing a smaller region but allowing you to pan across the canvas. Now when you set the scrollview's frame size and the content size to be same, the purpose is defeated. Hence no scrolling.

When you define the scroll view's frame to be 320x800 on a window/view that is of size 320x480, part of the view is clipped off. It is not visible but its there. You content is there too. What you need to do is to set the scroll view to match the window's size i.e. 320x480. Now you will have scrolling as the perspective is smaller than the canvas.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜