如何实现类似于Facebook或Instagram的新闻源评论页面 [英] How to implement newsfeed comment page similar to Facebook or Instagram

查看:99
本文介绍了如何实现类似于Facebook或Instagram的新闻源评论页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Instagram和Facebook都允许其用户对新闻源发表评论.在评论场景中,他们基本上有一个带有所有评论的UITableView和一个页脚",用户可以在其中输入评论并发布它们.因此,页脚"是带有UITextField/UITextView和UIButton的UIView或UIToolBar.从外观上看,这是真正简单的东西.好吧,我一直在尝试实现它,而键盘却没有配合.我需要键盘不隐藏页脚".特别是现在在iOS 8中,键盘带有建议工具栏,用户可以选择显示或隐藏该工具栏.所有这些交互使得在用户输入文本时很难将我的页脚"保持在键盘上方.每次我想确定解决方案时,我都会发现许多错误.

Both Instagram and Facebook allow their users to comment on news feeds. In the comment scene, they basically have a UITableView with all the comments and a "footer" where user may enter comments and post them. So the "footer" is a UIView or UIToolBar with a UITextField/UITextView and a UIButton. Truly simple stuff from the look of it. Well I have been trying to implement it and the keyboard is not cooperating. I need the keyboard to not hide the "footer". Especially now in iOS 8 the keyboard comes with a suggestions tool bar that a user may choose to show or hide. All these interactions make it difficult to keep my "footer" right above the keyboard while user is entering text. Every time I think I nail the solution, I find a multitude of bugs.

  • 在一个实现中,我使用键盘通知来侦听键盘是向上还是向下(部分基于

  • In one implementation, I use keyboard notification to listen for when the keyboard is up or going down (partly based on iPhone Keyboard Covers UITextField). The problem with this implementation is that there is a lag of about 1 to 2 seconds for when the keyboard shows up and for the "footer" to climb to the top of the keyboard from the bottom of the screen. A second issue is when user drags the suggestion toolbar to either show or hide it while typing, it causes my "footer" to move in unpredictable manners: which means I will need some static variables to meticulously track cumulative interactions with the suggestion toolbar just to fix that bug. Also notice that I put "footer" within quotation marks. That’s because I am not referring to a UITableView footer. But rather a view that I create beneath the table view as suggested by UITableView, make footer stay at bottom of screen?

我尝试的另一个实现是使用页脚"和键盘ToolBar.当用户单击页脚的UITextField时,这将导致键盘显示页脚的副本作为inputAccessoryView.基本上,这是在视觉上欺骗用户,使用户认为它是与键盘无缝爬升的页脚.但实际上,我使用的是两种复合视图:页脚"和键盘工具栏.我遇到的第一个问题是,我似乎无法以编程方式使工具栏文本字段成为第一响应者.这实际上曾经在ios-7中工作.但是,由于我更新到iOS-8,因此无法正常工作.因此,如果我执行footerTextField.inputAccessoryView=keyboardToolBar,然后在textfield委托方法中检查if(textField==footerTextField){[tooBarTextField becomeFirstResponder];},iOS-8只会忽略整个操作,或者更糟的是,完全关闭键盘和工具栏,因此实际上,当我因为显示和关闭是如此之快,所以请单击footerTextField.因此,这再次适用于iOS-7,但在iOS-8中却不起作用.

Another implementation I tried was to use a "footer" and a keyboard ToolBar. When user clicks on the UITextField of the footer, that would cause the keyboard to show up with a replica of the footer as inputAccessoryView. This is basically to visually fool the user into thinking it’s the same footer that seamlessly climbs with the keyboard. But in reality I am using two compound Views: a "footer" and a keyboard toolbar. The first problem I encounter with this one is that I cannot seem to make the tool bar text field the first responder programmatically. This actually used to work in ios-7. But since I updated to iOS-8 it does not work. So if I do footerTextField.inputAccessoryView=keyboardToolBar and then in the textfield delegate method check if(textField==footerTextField){[tooBarTextField becomeFirstResponder];}, iOS-8 just ignores the whole thing or, worse, dismiss the keyboard and the toolbar altogether, so that in fact the keyboard never shows up when I click on footerTextField since the showing and dismissing happen so quickly.So again this used to work in iOS-7, but in iOS-8 it does not work.

第三种方法是使父视图成为TPKeyboardAvoidingScrollView,这样我就可以拥有父,子UITableView和页脚".在这里,尽管TPKeyboardAvoiding在应用程序的其他场景中对我有用,但无论出于何种原因,它在这里都不起作用.我的猜测是因为我将UITableView用作UIScrollView的子级之一.

a third approach was to make the parent view a TPKeyboardAvoidingScrollView such that I would have parent, and children UITableView and "footer". Here while TPKeyboardAvoiding have worked for me on other scenes in the app, for whatever reason it’s not working here. My guess is because I am using a UITableView as one of the children of a UIScrollView.

第四种方法是使我的页脚"成为实际的UITableView节页脚;节页脚,因为我希望它浮动在底部.页脚页脚的问题是它们不固定在底部,这在滚动表时给用户视觉上不稳定的体验.

a forth approach was to make my "footer" an actual UITableView section footer; section footer because I want it to float at the bottom. The problem with section footer is that they don’t stick to the bottom, which gives a visually erratic user experience as you scroll the table.

好的,我已经说了很多.那么,最后,有没有人实现类似于Facebook/Instagram的NewsFeed Comment场景的场景?如果是这样,您能帮我吗?

Ok, so I have said a lot. So finally, has anyone implemented a scene similar to Facebook’s/Instagram’s NewsFeed Comment scene? If so, will you please help me?

回顾一下:Facebook/Instagram输入文本字段随文本增长;无论键盘的建议工具栏是显示还是隐藏,它始终停留在键盘的顶部;键盘移开时,鼠标停留在屏幕底部.

To recap: the Facebook/Instagram input textfield grows with text; sticks to the top of the keyboard whether the keyboard's suggestion toolbar is showing or hidden; sticks to the bottom of the screen when the keyboard is gone.

推荐答案

SlackTextViewController 似乎合适您所有的要求,而且写得很好.

SlackTextViewController seems to fit all your requirements and is very well-written.

这篇关于如何实现类似于Facebook或Instagram的新闻源评论页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆