简体   繁体   English

如何将子视图添加到uiscrollview以开始内容(在第一个子视图之前)?

[英]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 :(. 将subview添加到内容的末尾很容易,但是我不知道如何添加subview来开始:(.。

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 您将需要将所有其他视图向下移动新视图的高度,还可以向视图的运动中添加动画,例如,如果您有5个视图,并且想要添加其他视图,则将将这5个视图移至底部(并可以应用动画),然后将此新视图添加到正确的位置

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 但是,正如我在评论中建议的那样,使用UITableView会更容易,每个单元格都是UITableViewCell ,并添加一个新的聊天项,您将使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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