您的位置:首页 > 移动开发 > Swift

swift中替换弹出键盘

2016-03-08 22:07 405 查看
    //MARK:--显示表情

    @objc private func inputEmoticon(){

        printLog("显示表情")

        /*

            去设置一个标志位,来剔除 动画对 键盘的影响

        */

        // 先注销第一响应者,然后再让 textView.inputView 有视图

        textView.resignFirstResponder()

        /*

            当 textView.inputView = nil 可以出现键盘

            当 textView.inputView = 自定义表情视图 弹出我们的表情

        */

        // 当inputView == nil的时候,我们让它显示表情键盘,否则显示系统键盘

        

        

        if textView.inputView == nil {

            //

            textView.inputView = emoticonView

        } else {

                textView.inputView = nil

        }

======================华丽的分割线===============最新分析-->>>=============

        //不管有没有弹出文本输入框,都注销第一响应者,然后把表情框添加到弹出界面中 然后弹出表情框

        //插入按钮界面 先注销第一响应者,替换弹出界面

        textView.resignFirstResponder()

        printLog("输入键盘")

        

        /*

        

        inputview == nil 的时候表示没有弹出界面

        

        textView = nil 的时候弹出的就是键盘

        textView.input = emoticonView 的时候就是弹出自定义的视图

        下面的判段的作用是显示消失界面, 不是对文本键盘的操作

        */

        if textView.inputView == nil{

            textView.inputView = EmoticonView

        }else{//此时有键盘的存在

            textView.inputView = nil

        }

        

        textView.becomeFirstResponder()

        

        textView.becomeFirstResponder()

        

    }

总体就是先取消第一响应者,添加inputView,然后在使用becomeFirstResponder,弹出来键盘

用途:弹出自定义输出盘,底部弹出界面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: