在动画期间将元素粘贴到键盘底部

时间:2015-07-21 19:48:22

标签: ios objective-c keyboard

我正在努力使用iOS 8中的键盘,试图在动画期间粘贴其上方的元素。就像在消息中一样,他们通过出现键盘来推动输入。我在这里找到了很多主题,但他们都说如何处理出现的键盘,但不解雇。似乎Apple使用其他一些曲线或通过解雇来加速,所以当关闭键盘时我有异步,而出现的动画完全同步。

这是我现在所拥有的:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideOrShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideOrShow:) name:UIKeyboardWillHideNotification object:nil];

- (void)keyboardWillHideOrShow:(NSNotification *)note {
    NSDictionary *userInfo = note.userInfo;
    CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    [self adjustFormContainerSize]; // Method opening orange card

    UIViewAnimationCurve curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
    UIViewAnimationOptions options = (curve << 16) | UIViewAnimationOptionBeginFromCurrentState;
    NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    self.buttonContainerBottom.constant = keyboardEndFrame.size.height;
    [UIView animateWithDuration:duration
                          delay:0.0
                        options:options
                     animations:^{
                         [self.view layoutIfNeeded];
                     }
                     completion:nil];
}

结果在模拟器中:http://monosnap.com/file/BwxJdthPGzCqJnxeQLEg5bb8smvxdb

向后动画有什么问题,如何同步?

1 个答案:

答案 0 :(得分:0)

我建议你使用

DAkeyboard

它是处理此问题的非常好的组件