我坚持尝试平滑地为具有自动布局约束的表格视图设置动画。我在我的 .h 中引用了约束“keyboardHeight”,并在 IB 中将其链接起来。我要做的就是在弹出时使用键盘为表格视图设置动画。这是我的代码:
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
NSValue *kbFrame = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
NSTimeInterval animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect keyboardFrame = [kbFrame CGRectValue];
CGFloat height = keyboardFrame.size.height;
[UIView animateWithDuration:animationDuration animations:^{
self.keyboardHeight.constant = -height;
[self.view setNeedsLayout];
}];
}
问题是动画块是瞬时的,我看到在键盘完成动画之前出现空白。所以基本上我在键盘动画时看到视图的白色背景。只要键盘正在动画,我就无法使动画持续。
我是以错误的方式接近这个吗?提前致谢!