3 Jul 2017

Programmatically get height of keyboard in swift 3 language in iOS app - Tutorial

Get keyboard height in swift3 tutorial with example

Introduction to the tutorial programmatically get height of keyboard in swift 3 language in iOS app 

With the introduction of different size of iPhone devices,  getting keyboard height is a pain for iOS developers. With the addition of suggestion toolbar above keyboard in iOS, it's necessary for iOS developers to get exact height of the keyboard so that they can meet the app requirements where they have to show button above keyboard when user is typing on text field or other input field. 

                               iOS sends notifications each time keyboard comes up or goes off from screen. We, iOs developers can take advantage of this notification. Below are the codes that gives keyboard height in swift 3 

Adding notification observers for  UIKeyboardWillShowUIKeyboardWillHide notifications

First we have to add notification observers to our class where we want to get keyboard height as soon as user start editing an input field. You can add them in viewWillAppear()

Adding selectors/methods definition for the notification observers added 

Remove observers 

You can remove observers in viewWillDisappear(). 

No comments:

Post a Comment