Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct approach for implementing vertical scrolling with UIScrollView

I know that I asked a question a few minutes ago, but I want to make a few points clearer before asking for the community's help. I'm new to iOS development, close to finishing my first app. The only thing standing in my way is this UIScrollView. I simply do not understand it, and could use your help.

This is in the detail view controller of a drill-down app with a tab bar. I have approximately 8 fields (for things like phone numbers and such) drawing from a .plist. Obviously, those take up enough room that I could use a little extra real estate. I would guess that it needs to be about the size of two views vertically, but I do not understand how to allocate that sort of space to a UIScrollView. Some tutorials I have read say that you don't even need to define it in the header, which I doubt and do not understand. Additionally, I do not understand how to simply get the app to smoothly scroll up-and down only. Apple's examples have constant move cycles that flip between horizontal pictures.

I doubt it makes very much a difference, but I have an image that is in the background. I'm going to load the view on top of that.

My question is broad, so I don't expect you to take the time to sit down and write out all of the code for me (and I wouldn't ask you to). Just an outline of quick, helpful tips would help me understand how to get this view to load in the context of my project.

Many thanks!

like image 599
Rob Johnson Avatar asked Dec 21 '22 09:12

Rob Johnson


1 Answers

It's fairly simple. Add a UIScrollView to your view. Add your fields and such to the scrollview. In viewDidLoad or somewhere similar, you need to set the contentSize on your scrollview. This is the "virtual" area that will be scrollable. This will generally be larger than the frame of the scrollview. In your case, you indicated it should be roughly double the width.

For instance, if you had a scrollview with a view inside, and you wanted to make sure the entire view is visible via scrolling:

self.scrollView.contentSize = self.contentView.frame.size;
like image 147
Nathanial Woolls Avatar answered Mar 01 '23 22:03

Nathanial Woolls