The text view being hidden by keyboard is a very common issue faced by iPhone/iPad developers. When you touch a text view, the text view becomes first responder and keyboard automatically appears. If the text view is lying somewhere in lower part of the screen, most probably it will get hidden under the keyboard. The solution is to scroll the text view up enough so that it comes above the keyboard. To do that, you need to add the text view in UIScrollView so that it can be scrolled up.
Here is the strategy:
- Whenever keyboard appear, check if it is hiding the text view or not.
- If it is hiding the text view, then scroll the text view up so that it becomes visible.
- When the keyboard disappears, then scroll the text view to its original position.
Here is the sample code (similar code used in Lekh Diagram):
First register for the keyboard appearing/disappearing event:
The handler for the keyboard appearing event:
And when the keyboard disappears:
The above code is used in "Lekh Diagram" ipad app. Lekh Diagrma is a sketch recognition diagramming app.
You can get the Lekh Diagram from app store:https://itunes.apple.com/us/app/lekh-diagram/id576124115
You can see how content in scrolled when the keyboard appears in the demo of Lekh Diagram:
Learn more about Lekh Diagram: http://www.avabodh.com/lekh