小编Mar*_*y W的帖子

Autolayout约束 - 键盘

我试图平滑地制作一个具有自动布局约束的桌面视图.我在我的.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)

事情是动画块是瞬时的,我看到在键盘完成动画之前出现了空格.所以基本上我看到视图的白色背景,因为键盘是动画.只要键盘是动画,我就无法使动画持续.

我接近这个错误的方式吗?提前致谢!

objective-c uikeyboard ios autolayout

33
推荐指数
3
解决办法
2万
查看次数

标签 统计

autolayout ×1

ios ×1

objective-c ×1

uikeyboard ×1