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 trialAdam Young
4,147 PointsHow to make keyboard display?
I added the code shown in the video, but when I tap the text field the keyboard is hidden behind the background image. I would appreciate if anyone could help me out.
Thanks, Adam
3 Answers
dexter foo
8,233 PointsHi,
ok so i had the same problem as you so i went to tinker around a bit. i realised the keyboard didnt appear for me for two reasons: 1) For my iOS simulator, under hardware > keyboard, the option Connect Hardware Keyboard was selected. This means that it will use your mac's keyboard instead of the simulator's keyboard. so i unchecked it.
2) When i clicked on the textField, it pulled up the keyboard but the text field disappeared. I think this is because it disappeared behind the image view whenever the method keyboardWillShow method is called. so i added the textfield as an outlet in viewcontroller and added self.view.addSubview(self.textField) after changing the textFieldBottomConstraint when the keyboard pops up under the keyboardWillShow method.
func keyboardWillShow(notification: NSNotification) {
if let userInfoDict = notification.userInfo, keyboardFrameValue = userInfoDict[UIKeyboardFrameEndUserInfoKey] as? NSValue {
let keyboardFrame = keyboardFrameValue.CGRectValue()
UIView.animateWithDuration(0.8) {
self.textFieldBottomConstraint.constant = keyboardFrame.size.height + 10
self.view.addSubview(self.textField)
self.view.layoutIfNeeded()
}
}
}
let me know if this helps!
Moderator Edited: Moved response from Comment section to Answer.
Adam Young
4,147 PointsHi Dexter,
I appreciate you taking the time and providing the solution!
Thanks, Adam
dexter foo
8,233 Pointsno problem at all :)
KOJI NAKAGAWA
11,261 PointsHi Dexter, this helped me a lot!!
I was facing the same problems with previous video. (keyboard does not show up) And I unchecked the iOS simulator 's "Connect Hardware Keyboard" and it worked.
Thanks!!