Ufuk Can Bicici
Ufuk Can Bicici

Reputation: 3649

IOS UIScrollView: Cannot scroll until the end of the content

I am trying to generate a scroll controller in a window with the UIScrollView class, which will contain numerous UIButtons, placed vertically. I set the size of the scroll view equal to the current view controller's root view, so that the scroll view covers the entire visible window. Then I generate the UIButtons I am going to add to the scroll view: I add each UIButton just in the below of the previous UIButton and I add the height of the current UIButton to a variable called "totalContentHeight". Finally, I set the height of the contentSize of the scroll view to this value, in the following line of code:

self.scrollViewForNewsButtons.contentSize = CGSizeMake(self.view.frame.size.width, totalContentHeight);

totalContentHeight is equal to numOfButtons*eachButtonsHeight after I add all the buttons to the scroll view.

The problem is, in the simulator, when I run the app and scroll until the end of the last button and release the mouse, the last two buttons bounces back such that they lie outside of the visible window. It is somewhat hard to express with mere words, so here are the images:

1)This is what I get when I scrolled until the end of the content and held the content at the last possible position it could be pushed:

scrolled pic

2)This is what I get after I released the mouse and the scroll view bounced back to its final position:

not scrolled pic

As you can see, the last two buttons are drawn outside of the visible area. It is like the scroll view's area covers the whole window plus the button area of the IPhone. I could not find a reasonable explanation for this. Am I setting the area size wrong or am I missing something else?

Upvotes: 2

Views: 5427

Answers (2)

Paras Joshi
Paras Joshi

Reputation: 20541

just set content size with calculation with your total button and its height...For Ex..

float yheight = totalButton * yourButtonHeight;
[yourScrollView setContentSize:CGSizeMake(320, yheight + 44)];

try this code...

Upvotes: 4

Ron
Ron

Reputation: 1047

And if you set the scrollview frame size the same as

self.view.bounds

Upvotes: 0

Related Questions