udacity / ios-nd-networking

Resources for Udacity's iOS Networking with Swift course.
MIT License
172 stars 88 forks source link

View does not reset properly when keyboard is hidden #2

Closed iannotian closed 5 years ago

iannotian commented 8 years ago

To recreate this issue, while on the Login page for the MyFavoriteMovies starter app, tap inside a UITextField and while the cursor is blinking (indicating you are currently editing the UITextField), quickly tap outside of the UITextField. If you're fast enough, the view will not reset back to zero, and it can eventually be pushed too far upward to interact with. I've attached some screenshots showcasing this:

screen shot 2016-07-30 at 1 20 53 pm screen shot 2016-07-30 at 1 24 02 pm

Note: I haven't tried this on an actual iOS device; I've only tried this through a simulator.

iannotian commented 8 years ago

Setting the view's y-coordinate to zero when keyboardWillHide() is called seems to fix this.

In LoginViewController.swift:

func keyboardWillHide(notification: NSNotification) { if keyboardOnScreen { view.frame.origin.y = 0 movieImageView.hidden = false } }

chadchabot commented 6 years ago

I'm also seeing this happen in the simulator as well as on a physical device.

I modified both the keyboardWillShow & keyboardWillHide methods:

    func keyboardWillShow(_ notification: Notification) {
        if !keyboardOnScreen {
            view.frame.origin.y = -keyboardHeight(notification)
            movieImageView.isHidden = true
        }
    }

    func keyboardWillHide(_ notification: Notification) {
        if keyboardOnScreen {
            view.frame.origin.y = 0
            movieImageView.isHidden = false
        }
    }

and that got the behaviour I wanted.

OwenLaRosa commented 5 years ago

Closing this out as there's a new version of the course.