ios - Cannot get correct UIScrollView height from its subviews -
this question has answer here:
inside viewdidload
of uiviewcontroller
create:
a uiscrollview
following code:
- (void)generatescrollview { _scrollview = [[uiscrollview alloc] initwithframe:_containerview.frame]; [_containerview addsubview:_scrollview]; [self generatecontentview]; }
where _containerview
uiview
created through interface builder following constraints:
then generate uiview
i'll use container ui elements:
- (void)generatecontentview { _contentview = [[uiview alloc] initwithframe:_scrollview.frame]; [_scrollview addsubview:_contentview]; }
then generate n ui elements (uitextview
, uiimageview
ecc..) , recalculate height of both contentview
, scrollview
following code:
- (void)recalculatescrollviewheight { cgrect contentrect = cgrectzero; (uiview *view in _contentview.subviews) { contentrect = cgrectunion(contentrect, view.frame); nslog(@"contentrect height: %f", contentrect.size.height); } _contentview.frame = cgrectmake(_contentview.frame.origin.x, _contentview.frame.origin.y, _contentview.frame.size.width, contentrect.size.height + [[uiapplication sharedapplication] statusbarframe].size.height + self.navigationcontroller.navigationbar.frame.size.height); nslog(@"_contentview height: %f", _contentview.frame.size.height); _scrollview.contentsize = _contentview.frame.size; }
the problem _scrollview
cuts of content because seems calculated height not correct. i'm struggling problem , can't seem find solution, know why calculated height it's not correct? missing property uiscrollview
or uiview
?
edit: result of 2 nslog
:
contentrect height: 180.000000
contentrect height: 360.000000
contentrect height: 540.000000
_contentview height: 604.000000
i've added 3 uiimageview
height of 180
result correct, 540 + 20 (status bar height) + 44 (navigation bar height), still scrollview
cuts pixels last image. there's no spacing between images, they're 1 after another
i've seen cases uiscrollview try , helpful offsetting in order incorporate navigation bar if it's hidden. have tried disabling property?
self.automaticallyadjustsscrollviewinsets
i assume have scrollenabled set yes? bit of shot in dark, noticed others resolving similar issues here disabling , re-enabling scrolling:
Comments
Post a Comment