Move screen up when keyboard appears in iPhone X

move scrollview up when keyboard appears ios swift
scroll view up when keyboard appears ios
move textfield up when keyboard appears swift 4
move view up when keyboard appears ios objective-c
how to make a uitextfield move up when keyboard is present objective-c
move tableview up when keyboard appears swift 4
how to make a uitextfield move up when keyboard is present swift 4
ios keyboard push view up

I use code below to move screen up and down when keyboard show and hide

override func viewDidLoad() {
    super.viewDidLoad()            
    NotificationCenter.default.addObserver(self, selector:#selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)    
}

@objc func keyboardWillShow(notification: NSNotification) {        
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        if self.view.frame.origin.y == 0{
            self.view.frame.origin.y -= keyboardSize.height
        }
    }        
}

@objc func keyboardWillHide(notification: NSNotification) {
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        if self.view.frame.origin.y != 0{
            self.view.frame.origin.y += keyboardSize.height
        }
    }
}

It works in all devices except iPhone x (I think the problem is iPhone X bottom wasted space)

Problem is that keyboard size change before shown and after that and cause the view go down and down and down...

Can anyone help?


Here it is, Use IQKeyboardManagerSwift

AppDelegate.swift settings

IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = false

In My ViewController

func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
    print(#function)
    if DeviceType.checkiPhoneX() {
        IQKeyboardManager.shared.keyboardDistanceFromTextField = 40.0
    }        
    return true
}

 func textViewDidEndEditing(_ textView: UITextView) {
    if DeviceType.checkiPhoneX() {
        IQKeyboardManager.shared.keyboardDistanceFromTextField = 0.0
    }
}

This is how i manage Keyboard for X.

Hope this may help you.

IOS/Xcode: How to Move View Up when Keyboard appears, The following animation will move your view (viewForLogin in this case) 200 pixels above when the user starts typing. The view will animate back to original  Then, change as needed when keyboard shows up: self.view.center = CGPointMake(self.originalCenter.x, /* new calculated y */); Finally, restore it when keyboard is hidden: self.view.center = self.originalCenter; Add animation sugar as you wish. You have more than one way to know when the keyboard appears.


You should also consider safe area insets

let endFrame = (userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue ?? CGRect.zero
let bottomSpace = keyboardValues.endFrame.maxY - keyboardValues.endFrame.minY - self.view.safeAreaInsets.bottom

And you should not be additive. These notifications may be posted multiple times. Use absolute values.

How to raise a UITextField when the keyboard shows, Because the system manages the showing and hiding of the keyboard in response to In iOS we use the NSNotificationCenter (or NotificationCenter if you're using Swift) to Add a leading constraint so we define an x value; Add a trailing constraint so we define a For now we will just move the view controller's view up. Lightly press and hold , then immediately drag the keyboard up or down the screen. You can also move a split keyboard up or down the screen. Just lightly press and hold , then immediately drag the keyboard up or down the screen.


Use UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey.

my keyboard appears half way up my screen, You must have undocked it. Look at the bottom-right hand corner of your iPad keyboard. You'll see the keyboard toggle. Hold it and you'll see  Simply press and hold the Home and power ON/OFF buttons at once for about 10 seconds until you see Apple logo on the screen.


How do I get my keyboard back down to the…, Apple · Mac · iPad · iPhone · Watch · TV · Music · Support; Shopping Bag. Cancel Call up the keyboard so that it is visible. At the very bottom right of the Touch and hold the icon and a small popup will appear giving you the choice to undock(​move it up to the middle of the screen) or split it. If you do either  Keyboard lag commonly appears when typing emails, texts, or when using Messages. Consequently, your iPhone or other iDevice ends up virtually unusable to type emails, respond to a text, enter web pages or anything involving the keyboard. Not Good. Try the following suggestions, from least invasive at the start of the list to most dramatic at


iPhone Apps 101, One solution for this is to move the view up when a keyboard is presented. keyboard. Right before a keyboard is shown on the screen, iOS will  You can control whether this feature is available in iPhone General Settings under Keyboard. 8 To type a variation on a symbol, hold down the key; a set of alternate symbols appears. For example, when you press and hold the dollar sign on the number keyboard, you see alternate currency symbols.


Move view when keyboard is shown (guide), This is a feature that was added back in iOS 5. You can move the keyboard around on the screen to make typing more convenient. Can I hook up a Macbook that has a badly cracked screen to an iPad and use the iPad as an external