0

In my storyboard I have a UIViewController that contains an image view and a text view:

enter image description here

In my class I already handle a tap gesture - when user taps anywhere outside of the text view - the keyboard disappears:

override func viewDidLoad(){
    super.viewDidLoad()

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
    view.addGestureRecognizer(tap)

}

func dismissKeyboard() {
    view.endEditing(true)
}

Now, as you can see on my screenshot, the textview is pretty low, so when user taps it and the keyboard appears - it covers part of the textview itself. I would like to either move it up so it's more visible above the keyboard or - preferably, if that's even possible - for the time of editing - expand the size of textview so it covers the rest of the screen (and comes back to its normal size after user is done with editing). Can you help me with that?

user3766930
  • 5,629
  • 10
  • 51
  • 104
  • to show textview when keyboard apper you have to use scrollview and in scrollview add imageview and textview and then use keyboard notification method to show textview. – riddhi Mar 18 '16 at 10:12
  • you can follow this http://stackoverflow.com/questions/29431968/how-to-adjust-the-height-of-a-textview-to-his-content-in-swift. – Sahil Mar 18 '16 at 10:27

2 Answers2

1

I think the better approach is to slide your View above keyboard. Here's an answer how to do so.

Community
  • 1
  • 1
Muhammad Hassan
  • 1,037
  • 1
  • 8
  • 22
  • Thanks, that looks reasonable! One more thing - looking at the code in that answer - is there a way of distinguishing if the keyboard is present or not? Currently when the keyboard appears the screen moves up, but when I click away to hide it fast enough, the screen goes dark in the part where keyboard was. It's exactly what @jonprasetyo wrote there - do you have any clue how could I check if the keyboard is present or not? – user3766930 Mar 18 '16 at 10:45
  • You're right. To avoid such scenario, you can set up required `Bool isKeyboardShown` by adding these two notifications. `UIKeyboardDidShowNotification` and `UIKeyboardDidHideNotification` – Muhammad Hassan Mar 18 '16 at 11:07
0

Use IQKeyboardManager It will handle everything regarding text field. https://github.com/hackiftekhar/IQKeyboardManager

Soham Ray
  • 215
  • 2
  • 4