我试图平滑地制作一个具有自动布局约束的桌面视图.我在我的.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];
}];
}
Run Code Online (Sandbox Code Playgroud)
事情是动画块是瞬时的,我看到在键盘完成动画之前出现了空格.所以基本上我看到视图的白色背景,因为键盘是动画.只要键盘是动画,我就无法使动画持续.
我接近这个错误的方式吗?提前致谢!