Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGuillermo Tame
18,583 PointsTextField not moving
This is my keyboardWillShow function on the newest version of swift and XCode.
@objc func keyboardWillShow(_ notification: Notification) { if let info = notification.userInfo, let keyboardFrame = info[UIResponder.keyboardIsLocalUserInfoKey] as? NSValue { let frame = keyboardFrame.cgRectValue textFieldConstraint.constant = frame.size.height + 20 print(textFieldConstraint.constant) } }
My textfield doesn't move. When I print the textFieldConstraint.constant the terminal prints 20.0. The frame.height is set to 0. Anyone have any idea
1 Answer
Chi-Shuo Chen
5,275 PointsThis is my version for your reference
@objc func keyboardWillShow (_ notification: Notification) {
if let info = notification.userInfo, let keyboardFrame = info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue {
let frame = keyboardFrame.cgRectValue
textFieldButtomConstraint.constant = frame.size.height + 10
}
}