0

I want to create a simple UIView over keyboard works in AutoLayout.

Here is an example of Yik Yak UIView.

enter image description here

I checked Show UIView with buttons over keyboard, like in Skype,Viber messengers (Swift, iOS) but didn't works well.

Community
  • 1
  • 1
user3662992
  • 688
  • 1
  • 6
  • 16
  • 1
    The link you found is not your problem. You just need get the keyboard height from keyboard notifications, and set the buttons at the right 'height' – zc246 Nov 11 '15 at 13:27

2 Answers2

4

Instead of using notifications, calculating sizes etc., why not use the inputAccessoryView? here is an example from Apple: https://developer.apple.com/library/ios/samplecode/KeyboardAccessory/Introduction/Intro.html

Moshe Gottlieb
  • 3,963
  • 25
  • 41
  • I tried to add a button to upload image but it didn't works will it seems only for clear or done https://github.com/SabatinoMasala/accessoryview-demo – user3662992 Nov 11 '15 at 14:35
  • 1
    Your example you gave is using calculating sizes based on notifications :) – sunshinejr Nov 11 '15 at 14:39
  • 1
    @sunshine, it does :-) but it's not explicitly needed for an accessory view, it's needed for what they're trying to do in their sample code. – Moshe Gottlieb Nov 11 '15 at 14:51
3

So, because of the availability of custom keyboards in iOS 8, you need to do few things in order to achieve view above the keyboard.

  1. First, add observers for UIKeyboardWillShowNotification and UIKeyboardWillHideNotification, this will make sure you got the newest frame of the keyboard.
  2. Second, add your constraint to bottom of the view. Also connect this constraint with your ViewController, to have it as a property.
  3. Third, in the methods when UIKeyboardWillShowNotification and UIKeyboardWillHideNotificationfire up, you can get the frame of the keyboard like: notification.userInfo[UIKeyboardFrameEndUserInfoKey], then change the bottom constraint you have in your ViewController accordingly (+ when showing, - when hiding).
sunshinejr
  • 4,834
  • 2
  • 22
  • 32
  • Thank you sunshine do you have a link to an example that I can Follow , am New to swift – user3662992 Nov 11 '15 at 14:11
  • 1
    See the link @iMoses provided, its actually using the method I described, look in ViewController and registering notifications, plus keyboardWillShow and WillHide methods. Just do it with swift syntax. – sunshinejr Nov 11 '15 at 14:50