How to make TextView accompany writing

1

I need Textview to accompany me when I write because if this does not happen I end up writing under the keyboard, I already gave an Up in the textview but it is very big and will end up getting really low. how do I get the textView I followed when I write

    
asked by anonymous 05.08.2015 / 16:28

2 answers

0

This code I created translating from Objective-C to Swift worked for me.

I'm not using scrollView and instead of moving textView.frame , I'm using contentInset to crawl the cursor.

override func viewDidLoad() {
    registerForKeyboardNotification()
    textView.delegate = self
}

func registerForKeyboardNotification() {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWasShown:"), name: UIKeyboardDidShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillBeHidden:"), name: UIKeyboardWillHideNotification, object: nil)
}

func keyboardWasShown(aNotification: NSNotification) {
    let info = aNotification.userInfo!
    let kbSize = (info[UIKeyboardFrameBeginUserInfoKey])!.CGRectValue.size
    let contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0)
    textView.contentInset = contentInsets
    textView.scrollIndicatorInsets = contentInsets
}

func keyboardWillBeHidden(aNotification: NSNotification) {
    let contentInsets = UIEdgeInsetsZero
    textView.contentInset = contentInsets
    textView.scrollIndicatorInsets = contentInsets
    textView.resignFirstResponder()
}

I think I'm pretty close to what we're looking for, it worked for me in Xcode 7 beta 4, I hope it helps.

    
07.08.2015 / 19:53
0

Recently I had a similar problem and used the TPKeyboardAvoiding library to resolve it. This library automatically moves the text boxes off the keyboard.

To use it place the textViews inside a TPKeyboardAvoidingScrollView, which extends UIScrollView. By nib you just add a UIScrollView object and change the Custom Class ) to TPKeyboardAvoidingScrollView.

    
05.08.2015 / 17:38