在UIKeyboardWillShowNotification之后,AutoLayout约束动画不起作用

时间:2013-12-13 19:00:14

标签: ios animation keyboard autolayout

由于某些原因我不明白,如果我在UIKeyboardWillShowNotification之后启动它,我的约束动画不起作用。我正在修改“底部空间”约束,以影响视图的高度。我期望的是相对于顶部视图的视图位置保持不变并向下扩展。但是,视图的高度会立即变为正确的最终高度并向上移动。然后,即使我从未改变“顶部空间”约束,也会将其设置为最初的位置。

如果我在UIKeyboardWillShow动画之前为视图设置动画,它可以正常工作,但我需要键盘的高度。

这是我的代码:

- (void) keyboardWillShow:(NSNotification *)nsNotification {
    NSDictionary *userInfo = [nsNotification userInfo];
    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    [UIView animateWithDuration:0.5 animations:^{
        _editingBoxContraint.constant = kbSize.height;
        [self.view layoutIfNeeded];
    }];
}

以下是一些图片:

enter image description here

动画开始时。

enter image description here

动画结束时

0 个答案:

没有答案
相关问题