Reputation: 11
I've made it so a textfield is always on top of the keyboard (like in the messages app, whatsapp...) but my problem is that this poses the table above it up too because everything is in a scrollview. How can i make it so the table resizes so it fits in the space between the keyboard and top of the screen.
Upvotes: 1
Views: 55
Reputation: 14904
For example:
tableView.frame = CGRectMake(0,0,100,200);
To setup this, you should check when the keyboard is present. With:
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(notification: NSNotification) {
yourTableView.frame = newFrame // use CGRectMake()
}
Read here more about usage of UIScrollView:
http://www.appcoda.com/uiscrollview-introduction/
Or by Apple:
Upvotes: 1