UITextView reverts animated setFrame: after resigning first responder
I have a UITextView that animates its frame when the keyboard appears like so:
- (void)keyboardWasShown:(NSNotification*)n {
double duration = [[[n userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration
delay:0.3
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect tfFrame = self.tf.frame;
tfFrame.origin.y = tfFrame.origin.y - kbSize.height + 86.f;
[self.tf setFrame:tfFrame];
}
completion:nil
];
}
There is another UITextField directly below this text field which also animates into place when the keyboard appears. After animation, when the keyboard appears, and I touch the second text field, all of the animations revert back into their original positions.
I've logged the frame's y value through each of the UITextField delegate methods to try to pinpoint where the field is changing, and it seems to change when the first field resigns first responder:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"did begin: %f", self.tf.frame.origin.y);
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"did end: %f", self.tf.frame.origin.y);
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"should end: %f", self.tf.frame.origin.y);
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"should return: %f", self.tf.frame.origin.y);
return YES;
}
From the console:
2015-03-27 did begin: 521.000000
2015-03-27 should end: 90.294118
2015-03-27 did end: 521.000000
So far I have:
Unfortunately, I don't know where to go from here. I believe this to be an issue with either first responder status on the text fields or autolayout. What should I start checking?
链接地址: http://www.djcxy.com/p/44310.html