I have a text view at the bottom of the view controller. When the user taps on it, the keyboard appears to allow the user to type in the text view. The keyboard covers the text view. How do I move the text view up so that the user can see the text view while the keyboard is visible?
keyboard covers view
Change the view frame origin y value of myField by the height of the keyboard:
Here is an example :
func getScreenSize() -> (height: CGFloat, width: CGFloat) { /
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
return (screenHeight, screenWidth)
}
func keyboardWillShow(sender: NSNotification) {
let screenHeight = getScreenSize().height
if let keyboardSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
if screenHeight < 800 { // no need for higher screen
var offSet = screenHeight - (myField.frame.origin.y + myField.frame.size.height)
offSet -= keyboardSize.height
if offSet < 0 {
self.view.frame.origin.y = offSet
}
}
}
}
func keyboardWillHide(sender: NSNotification) {
self.view.frame.origin.y = 0
}Have a look at the details at http :// stackoverflow.com/questions/25693130/move-textfield-when-keyboard-appears-swift