Chat Input Accessory View
Tinder Firestore Swipe and Match
There are a ton of chat applications out on the market right now, all of them have quite a complex chat input area that allows for text, emojis, and images. Something else about this chat input that you might not have noticed is that it follow the keyboard and scrollview as you scroll up and down. This is a tricky feature to implement correctly, but using a custom InputAccessoryView allows for this behavior. Let's implement this in today's lesson.

Comments (7)
4 years ago
To get rid of the wonky behavior, I removed the keyboard observer and added a delegate to textview. This additionally gives me more control over what the user is doing with the textview. I have been working on an application for my dojo in Japan for about five months now. Created a short video with the auto-scroll and textview animation I have for the comment section. func textViewDidBeginEditing(_ textView: UITextView) { scrollToLastItem() } fileprivate func scrollToLastItem() { self.collectionView.scrollToItem(at: [0, items.count - 1], at: .bottom, animated: true) }
4 years ago
Good suggestion, and I think u need to add the following syntax to pull up the collectionview by the height of the keyboard, otherwise the bottom of the content is hidden by the keyboard. collectionView.contentOffset = .init(x: 0, y: 390-navbarHeight+20) . ps. 390 is the height of the keyboard. put the syntax above everytime textfield did begin editing
Nathan Hsiao
4 years ago
Hi Brian I try the code override becomefirstresponder and inputaccessoryview but the redview doesnt show up at all
David Guarino
3 years ago
need to add "can".....use ....canBecomeFirstResponder....
4 years ago
Hey Brian! Why don't we use an UITextField instead of a UITextView? As it already has .placeholder property? Thanks!
Alex Ruben Constancio
3 years ago
Hey Brian, When I go to dismiss my keyboard I am getting this error message below, It doesn't cause my app to crash but it is causing some glitchy behavior in my collection view - [View] First responder warning: '<UITextView: 0x7f869b859000; frame = (10 0; 354 40); text = 'Message...'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x6000012d90b0>; layer = <CALayer: 0x600001cc21e0>; contentOffset: {0, 0}; contentSize: {354, 28}; adjustedContentInset: {0, 0, 0, 0}>' rejected resignFirstResponder when being removed from hierarchy Thanks for any help!
3 years ago
Hi Brian, is "textView.insertTextPlaceholder(with: <#T##CGSize#>)" a workaround with Swift5 to the the 'placeHolderLabel' used in this session? Thanks a bunch.
3 years ago
When I click on the inputAccessoryView, it stretches becoming half of the view.frame.width, I don't know why
3 years ago
Great episode. Thank ya ?