user3766930
user3766930

Reputation: 5829

how can I expand the size of UITextView when user starts typing in it?

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?

Upvotes: 0

Views: 200

Answers (2)

Soham Ray
Soham Ray

Reputation: 215

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

Upvotes: 0

Muhammad Hassan
Muhammad Hassan

Reputation: 1047

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

Upvotes: 1

Related Questions