I have a UIViewController
with two containers embedded and one textfield. So far when user taps the textfield the whole screen moves up so the keyboard can fit without covering the lower part of the containers.
This is how it looks in my story board:
My code looks as follows:
override func viewDidLoad() {
super.viewDidLoad()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
// view.addGestureRecognizer(tap)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillChangeFrameNotification, object: nil)
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
if(isKeyboardShown == false){
realKeyboardSize = CGRect(x: keyboardSize.origin.x, y: keyboardSize.origin.y, width: keyboardSize.width, height: keyboardSize.height)
isKeyboardShown = true
self.view.frame.origin.y -= realKeyboardSize!.height
}else{
isKeyboardShown = false
self.view.frame.origin.y += realKeyboardSize!.height
}
}
}
Is it possible to move the lower container up instead of the whole screen?
I imagine it working like this:
topContainer
stays untouched, lowerContainer
moves up so that half of it is hidden behind topContainer
and the keyboard is visible. When user hides the keyboard everything comes back to normal.