A
A
Aleksandr Govorukhin2018-01-28 08:11:16
Swift
Aleksandr Govorukhin, 2018-01-28 08:11:16

How to hide textView while typing Swift 4?

Hello!
There is a table and in one of the custom cells there is a text View, the fact is that when entering any text, the keyboard closes the entire screen and the entered text is simply not visible, how to make the screen automatically scroll down when entering text?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleksandr Govorukhin, 2018-02-01
@SnapSh0t

The easiest way, I spent more than a week on this solution:
Download the IQKeyboardManagerSwift library.
After:

func textViewDidChange(_ textView: UITextView) {
        let size = textView.bounds.size
        let newSize = textView.sizeThatFits(CGSize(width: size.width, height: CGFloat.greatestFiniteMagnitude))
        
        if size.height != newSize.height {
            UIView.setAnimationsEnabled(false)
            tableView?.beginUpdates()
            tableView?.endUpdates()
            UIView.setAnimationsEnabled(true)
        }
    }

The perfect solution!

D
doublench21, 2018-01-28
@doublench21

scrollToRow(at:at:animated:)put in the desired delegate method UITextView.
https://developer.apple.com/documentation/uikit/ui...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question