715515390@qq.com
715515390@qq.com
  • 发布:2017-04-07 17:58
  • 更新:2019-03-24 10:30
  • 阅读:2753

IOS分享软键盘弹出,在键盘上方出现自定义菜单样式

分类:Native.js
var oH=0;  
            mui.plusReady(function() {  
                initNativeObjects();  
                showSoftInput();                  
                if(plus.os.name=="Android"){  

                }else{  
                    var iosH=plus.screen.resolutionWidth*plus.screen.scale;  
                    if(iosH==640){ //iphone5  
                        oH=screen.height-271;  
                    }  
                    if(iosH==750){ //iphone6  
                        oH=screen.height-258;  
                    }  
                    if(iosH==1080){ //iphone6 plus  
                        oH=screen.height-226;  
                    }  
                }                 

            });  
            function goFooter(oh){  
                $('.say-menu').animate({'bottom':oh},200);  
                $('.text-sum').animate({'bottom':oh+50},200);  
            }  
            $(function(){  
                /*var x=20,oH=$(window).height(); alert(oH);  
                $(window).on('resize',function(){  
                    var oH2=$(window).height();alert(oH2);  
                });*/  
                $("textarea").on('blur',function(){  
                    $('.say-menu').animate({'bottom':0},200);  
                    $('.text-sum').animate({'bottom':50},200);  
                });  
                $("textarea").on('focus',function(){  
                    $('.say-menu').animate({'bottom':oH},200);  
                    $('.text-sum').animate({'bottom':oH+50},200);  
                });  
            });  
            var nativeWebview, imm, InputMethodManager;  
            var initNativeObjects = function() {  
                if (mui.os.android) {  
                    var main = plus.android.runtimeMainActivity();  
                    var Context = plus.android.importClass("android.content.Context");  
                    InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");  
                    imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);  
                } else {  
                    nativeWebview = plus.webview.currentWebview().nativeInstanceObject();  
                }  
            };  
            var showSoftInput = function() {  
                var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();  
                if (mui.os.android) {  
                    //强制当前webview获得焦点  
                    plus.android.importClass(nativeWebview);  
                    nativeWebview.requestFocus();  
                    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);  
                } else {  
                    nativeWebview.plusCallMethod({  
                        "setKeyboardDisplayRequiresUserAction": false  
                    });  
                }  
                setTimeout(function() {  
                   //此处可写具体逻辑设置获取焦点的input  
                   var inputElem = document.querySelector('textarea');  
                    inputElem.focus();   
                    goFooter(oH);  
                }, 200);  
            };
2 关注 分享
DCloud_heavensoft bishuihanshan

要回复文章请先登录注册

kevinxu

kevinxu

mark
2019-03-24 10:30
bishuihanshan

bishuihanshan

支持
2017-12-20 13:57
EthanQu

EthanQu

回复 DCloud_heavensoft :
可有完整源码?
2017-10-16 16:55
605341780@qq.com

605341780@qq.com

回复 DCloud_heavensoft :
??是不是点击“分享”弹出软键盘
2017-06-24 10:56
605341780@qq.com

605341780@qq.com

不知怎么用这段js
2017-06-24 10:46
DCloud_heavensoft

DCloud_heavensoft

给个截图更直观,让大家知道什么情况需要用这段代码。
2017-04-08 01:47