steve8918
steve8918

Reputation: 1860

Confusion with UIScrollView and setContentSize

In Xcode 3, I followed a tutorial on UIScrollView that told me to set the size of my View to be 320x650, and then drag a ScrollView on top of that View. After adding:

[scrollView isScrollEnabled:YES];
[scrollView setContentSize:CGMakeSize(320, 650)];

in the viewDidLoad, and after attaching all the outlets properly, everything worked, I was able to see the scroll bars when I tried moving the screen up and down.

However, when I tried the same tutorial in Xcode 4.2, it didn't work, ie. I couldn't scroll the view. It appears that I need to set the content size to be larger than the size of the ScrollView.

Is this something that changed in XCode 4.2, or was the original tutorial wrong?

Should the size of the scrollView always be 320x480? I no longer understand the semantics of what this all means now, ie. why I need to setContentSize of the scrollView, but also set the size of the scrollView in Interface Builder. When I initially drag the scrollView on top of a View, it comes out the same size as the View. Is this wrong?

Upvotes: 0

Views: 3866

Answers (1)

bbarnhart
bbarnhart

Reputation: 6710

For a UIScrollView, the contentSize is generally going to be larger than the frame size of the UIScrollView. The point of setting contentSize is to tell UIScrollView how large its scrollable area is. When the user drags the content around, the UIScrollView will know how far it can drag it left or right or up or down.

Upvotes: 2

Related Questions