UITextField when the first responder resigns, causing a strange text scroll animation

I have several UITextFields implemented in a UITableView for an entry form. When the first responder resigns for the first time , a strange jump in animation occurs. Since they are almost completely built in Interface Builder with a .xib file, I have almost no code to add. But here is a funny .gif that shows the behavior:

Llegf.gif

Update:

I narrowed it to the point that I listen to keyboard events to adjust view restrictions. This is the code 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 the view in which the button for viewing the table and entry is located.

+7
ios uitextfield swift interface-builder
source share
2 answers

It looks like a total hack (and I would like someone to post a better answer), but at the same time I solved it by adding a slight delay to the animation - I suspect that this is due to become and resignFirstResponder events that occur 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() } } 
+4
source share

try it

 - (void)textFieldDidEndEditing:(UITextField *)textField { [textField layoutIfNeeded]; } 
+1
source share

All Articles