ios - UIScrollview jumps off screen when switching between views -


i have tab-bar app scroller view in first tab , other stuff in second one. scrolling works fine, if scroll down , switch second tab , again scrollview jumped far whole thing out of frame , can barley scroll , reach half way top. if go second tab , tab scroll view again in spot fine, every time switch first time run app flies far off screen.

so added method thought fix problem, , looks this:@property (nonatomic) float lastscrollheight;

@synthesize lastscrollheight = _lastscrollheight;  -(float)lastscrollheight{     if(!_lastscrollheight) _lastscrollheight = 0;     return _lastscrollheight; }     -(void)viewdidlayoutsubviews{     [super viewdidlayoutsubviews];     [self.scroll setcontentoffset:cgpointmake(0.0f, self.lastscrollheight) animated:no]; }  -(void)viewwilldisappear:(bool)animated{     [super viewwilldisappear:animated];     self.lastscrollheight = self.scroll.bounds.origin.y;     [self resetapplesbrokenscrollview]; }  -(void)resetapplesbrokenscrollview{     [self.scroll setcontentoffset:cgpointzero];     cgrect sframe = self.scroll.bounds;     sframe.origin = cgpointzero;     self.content.bounds = sframe;     cgrect cframe = self.scroll.frame;     cframe.origin = cgpointzero;     self.content.frame = cframe; } 

and inside viewdidload method :

[super viewdidload]; [scroll setscrollenabled:yes]; [scroll setcontentsize:cgsizemake(320, 1900)]; scroll.contentinset=uiedgeinsetsmake(0.0,0.0,1919.0,0.0); 

and i'm pretty confident code, seams wrong... appreciated. thx :)

even if have long list, thats why set contentsize. immense bottom inset makes no sense cause way out of screensize.height.

if have f.i. view overlapping scrollview need provide contentinset height of overlapping view (just example).

your scrollview frame should size want content scroll in. contentsize actual size content takes/needs.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -