views:

6774

answers:

3

I've been having a very hard time finding good examples of UIScrollView. Even Apple's UIScrollView Suite I find a bit lacking.

I'm looking for a tutorial or example set that shows me how to create something similar to the iPhone Safari tab scrolling, when you zoom out from one browser window and can flick to others.

But I'm having a hard time just getting any old view showing within a scroll view. I have a view set up with an image in it, but when I add it to the scroll view, I only get a black rectangle, no matter what I put in the view I add.

Any links or code snippets would be great!

A: 

Hi,

There are lots of tutorials on TEH INTARWEP. A quick google search should return a large number of results.

Here are two:

x. www.iphonedevsdk.com/forum/iphone-sdk-tutorials/3393-uiscrollview-tutorial.html

  • Has a video

x. www.iphonedevsdk.com/forum/iphone-sdk-development/17678-best-practices-uitableview-within-uiview-within-uiscrollview.html

  • Not a tutorial

  • Discussion on different levels of embedded subviews.

Try searching for "iPhone Programming UIScrollView" at google and you'll probably get lots of results.

-isdi-

ISDi
I've seen those and they don't go sufficiently in detail. I am familiar with the INTARWEP and googling hasn't provided anything useful. Nobody chooses to go into detail onto basic IB settings to elicit behavior, etc. Even Apple's documentation sucks on this.
Jasconius
It really doesn't. I found it sufficient.
Sneakyness
+7  A: 

Here is a quick but workable example of a simple view inside a UIScrollView.

The basic steps are:

  1. Create a UIScrollView and a content view you want to put inside (in your case a UIImageView).
  2. Make the content view a subview of the scroll view.
  3. Set the content size of the scrollview to the frame size of the content view. This is a very important step that people often omit.
  4. Put the scroll view in a window somewhere.

As for the paging behavior, check out UIScrollView’s pagingEnabled property. If you need to scroll by less than a whole page you’ll need to play tricks with clipsToBounds, sort of the reverse of what is happening in this StackOverflow question.

Ben Stiglitz
EDIT: found my question here: http://stackoverflow.com/questions/1135163/how-do-i-use-uiscrollview-in-interface-builder - and sadly the answer is "no, Apple forgot to enable it". ORIGINAL COMMENT: Is there any way to do STEP 3 above from within Interface Builder? I've been doing it in code, unable to find a way in IB. It's odd - basically, it seems Apple is forcing you to write code if you ever want a UIScrollView to actually work?
Adam
A: 

Thanks a lot, I've been searching everywhere for some real information on ScrollView. Even the guy who wrote this book I bought got it wrong (setting the scroll content size correctly)

Chris