Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with UIScrollView Content Offset

Im developing an iPad app in which I have a scrollview, the size of which i determine dynamically depending on the number of objects i display in it. Now, though i have not set any content offset I find that the scroll view has been offset by some amount whenever the view loads. When I check the value of the offset, it shows 0. I dont understand why without having a contentOffset value, the scrollview behaves that way. Any reasons for this?

I suspect this has something to do with iOS 4.2 as i dont remember this problem occurring when i was testing the app on iOS 3.2.

Update: The amount its getting offset seems to vary based on the contentSize of the scrollView. If the contentSize of the scrollView matches that of its frame height (its a vertical scrollview), then there is no offset. As the contentSize increases above the value of the height of the scrollView frame, the offset also increases proportionally. However, scrollView.contentOffset.y still = 0.0

like image 963
Nathan Avatar asked Apr 25 '26 06:04

Nathan


1 Answers

if u use interface builder -

  • add scrollview to the view
  • create another view and add elements that u need to add to scroll view

then add this second view to scrollview

write this code in Viewdidload scrollview.contentsize.y = lastelement.frame.origin.y + lastelement.frame.size.height + 10

this will adjust the scrollview to content size. it displays the first element and can scroll from top to bottom.

like image 106
Krishna Chaitanya Bandaru Avatar answered Apr 27 '26 00:04

Krishna Chaitanya Bandaru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!