简体   繁体   中英

How to add subview to uiscrollview to start of content (before first subview)?

I write a chat module and i need to load previous messages to chat when user scrolling up a chat view. It is so easy to add subview to end of content, but i don't know how to add subview to start :(.

You will need to shift all the other views down by the height of the new view, you can also add an animation to the motion of the views, for example if you have 5 views, and you want to add an additional view, you will shift these 5 views to the bottom (and maybe apply an animation) then add this new view to the correct postition

However as i suggested in the comments, using a UITableView would be easier, each cell will be a UITableViewCell , and to add a new chat item you would use

[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
                 withRowAnimation:UITableViewRowAnimationRight];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM