I've got a couple of UITextFields implemented in a UITableView for a login form. When resigning first responder in both the very first time, a really strange animation jump is occurring. Since these are almost entirely build in Interface Builder with a .xib file, I've got virtually no code to add in. But here's a fun .gif that shows the behavior:
Update:
I've narrowed it down to the fact that I'm listening to keyboard events to adjust the view constraints. This is the code that's causing the problem:
func keyboardWillHide(notification: NSNotification) {
// tried self.formContainer.layoutIfNeeded() here too to force pending layouts
formContainerYConstraint.constant = 40
UIView.animateWithDuration(0.4) { () -> Void in
self.formContainer.layoutIfNeeded()
}
}
... where the form container is a view that houses the table view and login button.
Feels like a total hack (and I'd love for someone to post a better answer) but in the mean time, I've resolved this by adding a slight delay to the animation action - I suspect this is related to the become- and resignFirstResponder events occurring when switching between two input fields.
let delay: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(delay, dispatch_get_main_queue()) { () -> Void in
self.formContainerYConstraint.constant = 40
UIView.animateWithDuration(0.4) { () -> Void in
self.formContainer.layoutIfNeeded()
}
}
Try this
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[textField layoutIfNeeded];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With