0

I create a chat program. I've created my chat sequence using TableView. Now I have a view on the bottom of the page, contains one TextField and a send button. Now if I press on the TextField, the keyboard appears. I need to:

  • reduce the height of the tableView so that I still can see the most recent chat message, and return it to its former height if the keyboard is hidden.
  • move the view up to sit on top of the keyboard, and return it to its former position if the keyboard is hidden.
  • do both of things above with animation.

I'm still newbie in this keyboard + animation area. I only know I will need to implement textFieldDidBeginEditing and textFieldDidEndEditing to do this. But I don't know what code I should implement inside it. This answer provided some, but not the exact answer to my problem (it only moves the floating TextField in the scrollable view of TableView to be within the visible area, not moving a view not related with TableView). Any help or even article will be appreciated. Thanks!

Community
  • 1
  • 1
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
  • you can use keyboard notification for this – Jagveer Singh Apr 13 '16 at 07:33
  • @ChenLiYong Are you using auto layout? – Jaimish Apr 13 '16 at 07:34
  • 1
    You can use [IQKeyboardManager](https://github.com/hackiftekhar/IQKeyboardManager) for manage textfield. Then you only have to reduce abd increase the size of tableView. Other stuff will be manage by this library. – Ketan Parmar Apr 13 '16 at 07:38
  • @JagveerSingh you mean UIKeyboardWillShowNotification? – Chen Li Yong Apr 13 '16 at 07:38
  • @Jaimish no I'm not. Is there any possibility that this is an easy thing to do if I'm using auto layout? – Chen Li Yong Apr 13 '16 at 07:39
  • If you want to use third party handler then see @Lion answer. – Jaimish Apr 13 '16 at 07:40
  • if you are using autolayout than check this .. http://stackoverflow.com/questions/31356293/uitableview-and-uiview-with-keyboardwillshow/31356527#31356527 – Bhavin Bhadani Apr 13 '16 at 07:41
  • @Lion I think that is a great solution. But unfortunately, when I add it to cocoapods and install it, the framework generates plenty of errors... (my Xcode ver 7.2.1, iOS deployment target 8.2). – Chen Li Yong Apr 13 '16 at 07:53
  • You can just drag and drop library to your project. No need to add it to cocoapods. Just add library to your project and everything will manage automatically. – Ketan Parmar Apr 13 '16 at 07:57
  • but issue is happen when you use IQKeyboardManager whole view will transform to top in your case – Jaimish Apr 13 '16 at 08:32

0 Answers0