views:

195

answers:

1

Hello,

I have a scrollview that I had to the view of the view controller pushed to a UINavigationController. My navigation bar is opaque.

However, the scrollview seems to keep size of the whole parent view. I would like the scrollview to have the size of the space between the toolbar and the navigationbar.

Is this possible or do I have to hardcode some size values?

Thanks in advance

+1  A: 

When you initialize your scrollView you can set its contentSize parameter:

 [scrollView setContentSize:CGSizeMake(320,392)];

The height of the screen (480) minus the toolbar (44) and navigation bar (44) = 392. Drop that to 372 if you're also displaying the carrier status bar.

or, use the frame geometry properties:

[scrollView setContentSize:CGSizeMake((scrollView.superview.frame.size.width),
                                      (scrollView.superview.frame.size.height -
                                       toolbar.frame.size.height - 
                                       navigationController.navigationBar.frame.height))];
chrispix
What if the next iphone gets a different resolution?
Kamchatka
I don't know exactly how your view is set up, so you may have to tweak this, but you can use the frame geometry properties: [scrollView setContentSize:CGSizeMake((scrollView.superview.frame.size.width),(scrollView.superview.frame.size.height - toolbar.frame.size.height - navigationController.navigationBar.frame.height))];
chrispix
Thanks for your help. Why are you setting contentSize and not frame.size? If I want the scrollview by itself to be between the navigation bar and the toolbar, shouldn't I rather change scrollview.frame.size?
Kamchatka
I use contentSize because that's what the API exposes: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.htmlI haven't tried setting frame size, though I imagine that setting contentSize does more behind the scenes. For example, think about how the scroll view bounces when you flick to the edge--it's showing pixels that are outside the contentSize. So presumably its frame is actually a bit bigger. UIScrollView also contains other subviews, so the result of setting its frame dimensions directly would be indeterminate.
chrispix