iPhone Recalculate Scroller Content Height? - iphone

I am adding a bunch of boxes into a UIView inside of a UIScrollerView. The content of the UIView goes beyond the bottom of the device's screen and should cause the whole scene to scroll.
However, this isn't happening. The content gets added but the scene will not scroll. I assume it has to do with UIKit not automatically resizing the UIView container to match the overflowed content (I can understand why), so I tried setting the new bounds rectangle with [container setBounds: CGRectMake(0, 90, 768, 230*20)], with the 20 being the number of boxes (the height of each is 230). When I do this, nothing appears at all...
Anyone know why the content doesn't reappear or does anyone have another solution for making the UIScrollView scroll?

You should set the contentSize of scrollview, to match your UIView's size.
Please see
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/instp/UIScrollView/contentSize

Related

ScrollView in iPhone interfacebuilder

I have put 14 items in scroll view but it gets stuck after 6 items. I have not put any code, just did all from interface builder (items are arranged vertically). I can see the items below but it jumps to 6 items when I release the touch. It is not that the scroll view is not working, it is just not showing as much I want it to show.
Has any-body got any idea what is happening? any help is appreciated.
You should set the content size of your scrollview.
e.g.
[scrollview setContentSize:CGSizeMake(scrollview.contentSize.width, heigth)];
Where set height that contains all your sub controls in scrollview.
Scrollview content size is not set properly. Use setContentSize: to set the content size of the scrollview
You added the content into scrollview so now you have to make scroll know to what size it shoul scroll and show the content
Do
Set an outlet and then add this code in viewDidLoad
[scrollview setContentSize:CGSizeMake(width, height)];
From Docs
contentSize
The size of the content view.
#property(nonatomic) CGSize contentSize
Discussion
The unit of size is points. The default size is CGSizeZero.
Here is a nice tutorial since you are a beginner .
may be its too late, but here is how i solved it:
put the items in a UIView and stretch that view as much as it need to be stretched.
put that UIView in the scrollview.
put a scroll view in the main uiview, the height and width will be similar to uiview.

UIScrollView only scrolls with text

I recently updated my xcode to 4.5 but now my UIScrollView Doesn't work anymore, in my previous xcode I made the scrollview at the exact same way and placed a imageview background and some buttons in it, they scroll along when I scroll.
Now with this new xcode when I place something in it, it doesn't scroll at all. Only when I put textview in it and make the text longer then the screen then it will scroll, but even then when I place a button on it the button won't scroll along, just the text. It's realy annoying and I don't know what Im doing wrong.. I've been trying to find a solution to this all day.
my ScrollView is placed in my view and got size 320,480.
in my ViewDidLoad I have:
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 481)];
I also have a picture to make my setup more clear, When I run the project in this picture it does scroll because of the text length. the image background is 320x960 but the picture doesn't scroll along it should go to the bottom where to color becomes more dark.. I hope you understand what I mean.
Extra
I made a video showing what I do, showing that it doesnt scroll when I put something in it
http://www.youtube.com/watch?v=rzYTWLiIC8g&feature=youtu.be
set your scrollView contentSizes height more than its original height then it would be vertically scrollable for sure.
Try this -
[scroller setContentSize:CGSizeMake(320, 800)];
Then see it scrolls or not.

UIScrollview only scrolls when empty

I updated xcode to 4.5 but now when I make à UIScrollview it stops scrolling as soon I place something in the scroll like à label or button, when I remove them the scrolls works again
someone knows the fix?
Code
My ScrollView is 320 by 430 and in my viewdidload I use:
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 481)];
edit
I just discovered that in landscape mode it does scroll so maybe I am setting my content size wrong? :S
edit#2
It works now if I make a text view in the scrollview and make the text larger then the screen, but When I place a button into it the button doesnt scroll along ..
Extra
I made a video showing What I do hope someone can tell me what im doing wrong
http://www.youtube.com/watch?v=rzYTWLiIC8g&feature=youtu.be
"Use Autolayout" was on it has to be off and it will be fixed thanks for all your support.
You don't have enough content for scrolling.
Please add more content text. Then only it scroll.
Set the contentSize of your scroll view to the size of the content, eg. if you have 10 rows of buttons, each row's height let's say 40px, and padding 5px, the height (height if you are putting the content vertically, width if horizontally) of the contentSize of the scroll view is: 10*45.0f+5.0f. If this doesn't help, then show us your code.

UIScrollView Updating contentSize Causes Scroll

I have a UIScrollView that has a single child view within it. If I set the contentSize of the UIScrollView immediately after creation, everything works as I expect and I get scrolling.
The challenge is the view within the UIScrollView is dynamically sized. The width is fixed, but the height is unknown at the time I set up the scrollview.
When I do a [scrollView setContentSize:CGRectMake(...)] after the inner view does it's thing, the scrollview updates to the proper size and scrolling works. So basic scrolling works fine.
However, the major problem is that when I setContentSize at a later point, the UIScrollView decides to scroll down(with animation) towards the end of the scrollview, which is not what I want, I want the scroll to stay at the top, and let the contents within the scrollview either get bigger or smaller, without changing the apparent scroll position.
What am I missing?
Why don't you also call [scrollview setContentOffset:CGPointMake(0,0)]; when you call the setContentSize?
To force UIScrollView to scroll only e.g. horizontally, I always set non-scrollable value for contentSize to 0, using:
CGSizeMake(contentSize.width, 0).

Hiding elements outside of bounds on iPhone

I'm trying to get a UIView to expand (with animation), sort of like an accordion menu. I can get the animation working fine however the issue is the subviews of the UIView are expanding past the bounds of the UIView.
For example, the view has an UILabel in the top-right corner with a height of 16. Assume the UIView height is 0 at the beginning of the animation. One would expect that the content of the view be hidden and gradually reveal as the UIView grows. Once the height has reached 8, for example, half the label should be visible. However that isn't the case - rather, the label is visible the whole time, regardless if it's height extends outside of that of it's parent view.
Any ideas how to resolve this?
Okay, I had to set the clipsToBounds property to true. I spent some time googling before making the question but didn't have much luck until I saw it in the Related section of my question.