I’m trying to recreate the built in messaging app’s view. I need to add talk bubbles to the bottom as well as prepend them on the top when i click “load previous”.
My main issue is that I don’t know how to push the rest of the talk bubbles down when i load more to the top. It’s been quite a struggle for me.
I’m working in a subclass of UIScrollView and i’ve added an “innerView” to that.
What i do is add labels(bubbles) to negative values on the top and positive values on the bottom. I store the last positions in “topLabelsPosition” and “bottomLabelsPosition”
Can anyone help with this? Here’s my code
CGFloat whereToScroll = 0.0;
CGFloat topOfContent = self.topLabelsPosition.origin.y;
CGFloat bottomOfContent = self.labelsPosition.origin.y;
CGFloat fullHeight = fabs(bottomOfContent)+fabs(topOfContent);
[innerView setFrame:CGRectMake(0,topOfContent,self.frame.size.width, fullHeight)];
if(is_adding_to_top) {
whereToScroll = topOfContent;
} else {
whereToScroll = bottomOfContent;
}
[self setContentSize:contentSize];
CGPoint point = {0, whereToScroll};
[self setContentOffset:point];
My “innerView” does not get bigger on top, but on bottom – i can tell by the background color.
And my scrollview won’t scroll to the -300.00 (topOfContent) like i want it to.
I’m open to rewriting whatever and I’m all ears if you’d be so kind as to help.
Thank you so much in advance!
If you look closely at the Messages.app it doesn’t scroll when it loads new bubbles at the top. they just blink in. As opposed to new messages appearing in the bottom where it scrolls them in.
I believe they aren’t adding them to the top so much as adding them to (0,0) then moving everything already in the scrollView down in the content view. So try not adding to -xxx y but rather 0+ y and adjusting the frames of everything already inside down by the same amount.
Hope this helps.