美文网首页iOS开发
iOS 键盘动画

iOS 键盘动画

作者: yitez | 来源:发表于2019-05-31 11:31 被阅读1次

    首先注册通知,监听键盘的变动:

       NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
       NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];
        [nc addObserverForName:UIKeyboardWillChangeFrameNotification
                        object:nil
                         queue:mainQuene
                    usingBlock:^(NSNotification *note){
                        [weakSelf keyboardWillChangeFrame:note];
                    }];
        [nc addObserverForName:UIKeyboardWillShowNotification
                        object:nil
                         queue:mainQuene
                    usingBlock:^(NSNotification *note){
                      [weakSelf keyboardWillShow:note];
                    }];
        [nc addObserverForName:UIKeyboardWillHideNotification
                        object:nil
                         queue:mainQuene
                    usingBlock:^(NSNotification *note){
                        [weakSelf keyboardWillHide:note];
                   }];
    
    

    键盘的frame和动画属性通知里都有,直接获取:

    - (void)layoutView:(NSNotification *)noti {
             //获取键盘高度
      NSDictionary *userInfo = notification.userInfo;
        CGRect endFrame   = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        _keyboardHeight = _isVisiable? endFrame.size.height: 0;
            //获取键盘动画属性
        UIViewAnimationOptions animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
        CGFloat animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
       [UIView animateWithDuration:animationDuration
                              delay:0.0
                            options:animationCurve
                         animations:^{
                      //改变界面布局
                         } completion:nil];
    }
    
    

    相关文章

      网友评论

        本文标题:iOS 键盘动画

        本文链接:https://www.haomeiwen.com/subject/dcrwtctx.html