Synchronizing Animations in keyboardWillShow keyboardWillHide — Hardware Keyboard & Virtual Keyboard Simultaneously

前端 未结 2 924
青春惊慌失措
青春惊慌失措 2020-12-29 08:25

Preamble

So I have an application featuring a chat section, and I\'m synchronizing the animation of the keyboard hiding and showing with the rise and fall of the

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 08:53

    keyboardWillShow:

    NSDictionary *info = [notification userInfo];
    CGRect keyboardFrame = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationCurve curve = [info[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    
    [self layoutIfNeeded];
    [UIView animateWithDuration:duration delay:0 options:(curve << 20) animations:^{
        [self.keyboardConstraint setConstant:keyboardFrame.size.height];
        [self layoutIfNeeded];
    } completion:nil];
    

提交回复
热议问题