There are many ways to achieve this but you always need to listen to keyboard related notifications to do it. They work the same way as the obj-c ones. The following simplified example shows how to move the text field up when the keyboard appears and move it back down when it gets dismissed. The following example is an implementation of UIViewController.
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self);
}
func keyboardWillShow(sender: NSNotification) {
let s:NSValue = sender.userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as NSValue;
let rect :CGRect = s.CGRectValue();
var frame = self.textField.frame;
frame.origin.y = frame.origin.y - rect.height;
self.textField.frame = frame;
}
func keyboardWillHide(sender: NSNotification) {
let s:NSValue = sender.userInfo.valueForKey(UIKeyboardFrameBeginUserInfoKey) as NSValue;
let rect :CGRect = s.CGRectValue();
var frame = self.textField.frame;
frame.origin.y = frame.origin.y + rect.height;
self.textField.frame = frame;
}