在iOS 6中一切正常.键盘打开并将输入移动到视图中.当键盘关闭时,一切都会回到应有的位置.
在iOS 7中,键盘打开正常,输入仍然在视图中.当键盘关闭时,应用程序的整个下半部分都消失了.我已经将问题跟踪到键盘打开时窗口高度的变化,并且在关闭时不会改变.
在键盘打开之前,窗口高度为568,根据$(window).height(),在打开后,它关闭后为828.文档的高度也相应改变.
我试图阻止窗口调整大小:
$(window).resize(function(e) {
e.preventDefault();
e.stopPropagation();
window.resizeTo(320,480);
return false;
});
Run Code Online (Sandbox Code Playgroud)
我还尝试在键盘关闭后设置尺寸,但没有成功.
我正在使用phonegap 2.7并将KeyboardShrinksView设置为true.
我也看到了这一点.高度变化后,我们的一些绝对定位元素从屏幕底部消失.
我发现在ios7中使用KeyBoardShrinksView = false,window.height保持不变.这与ios6相反,所以有点像22.
不确定在Phonegap中是否有更好的方法来处理它,但我把它放在CDVViewController.m中,为ios <v7和ios> v6的config.xml文件创建,我的应用程序以我想要的方式工作.看起来有点hacky,但不会破坏我的其余代码.
// read from config.xml in the app bundle
NSString* path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"xml"];
if (IsAtLeastiOSVersion(@"7.0")) {
path = [[NSBundle mainBundle] pathForResource:@"config_ios7" ofType:@"xml"];
}
Run Code Online (Sandbox Code Playgroud)
(我也在https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ApplicationPreferences尝试了一个应用程序首选项插件,但不认为这是为这种偏好设计的.)
用cordova 3.1将项目升级到iOS后,我开始遇到输入字段的类似问题,我没有上面列出的代码.键盘推动了事情,页眉和页脚没有返回原来的位置.我已经测试并解决了问题(可能不是很优雅,但它是一种解决方法).我只是将该代码放在我的pageinit事件上.
/*************************************************************************************************
* FIX: to avoid the buggy header and footer to jump and stick not
* to the top/bottom of the page after an input or textfield lost focus and the keyboard dissapear *
*************************************************************************************************/
$('input, textarea')
.on('focus', function (e) {
$('header, footer').css('position', 'absolute');
})
.on('blur', function (e) {
$('header, footer').css('position', 'fixed');
//force page redraw to fix incorrectly positioned fixed elements
setTimeout( function() {
window.scrollTo( $.mobile.window.scrollLeft(), $.mobile.window.scrollTop() );
}, 20 );
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14545 次 |
| 最近记录: |