Phonegap:键盘在 iOS 7 中更改窗口高度 [英] Phonegap: Keyboard changes window height in iOS 7

查看:23
本文介绍了Phonegap:键盘在 iOS 7 中更改窗口高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS 6 中一切正常.键盘打开并将输入移动到视图中.当键盘关闭时,一切都会回到应有的位置.

In iOS 6 everything works fine. The keyboard opens and moves the input into view. When the keyboard closes everything goes back where it should.

在 iOS 7 中,键盘打开正常,输入保持在视图中.但是,当键盘关闭时,应用程序的整个下半部分都消失了.我已经将问题追溯到键盘打开时窗口高度发生变化,而键盘关闭时窗口高度不发生变化.

In iOS 7 the keyboard opens fine and the input remains in view. When the keyboard is closed the whole bottom half of the app is gone, though. I've tracked the issue down to the height of the window changing when the keyboard is opened, and not changing back when it's closed.

在键盘打开前窗口高度根据$(window).height()是568,打开后和关闭后都是828.文档的高度也相应变化.

Right before the keyboard is opened the window height is 568 according to $(window).height() and after it's opened and after it's closed it is 828. The height of the document also changes accordingly.

我尝试通过以下方式阻止窗口调整大小:

I've attempted preventing the window from resizing with:

$(window).resize(function(e) {
   e.preventDefault();
   e.stopPropagation();
   window.resizeTo(320,480);
   return false;
});

我还尝试在键盘关闭后重新设置大小,但没有成功.

I've also attempted to set the size back after the keyboard closes with no success.

我正在使用 phonegap 2.7 并将 KeyboardShrinksView 设置为 true.

I'm using phonegap 2.7 and have KeyboardShrinksView set to true.

推荐答案

我也看到了这个.高度改变后,我们的一些绝对定位元素会从屏幕底部消失.

I was seeing this too. After the height changes, some of our absolute positioned elements disappear off the bottom of the screen.

我发现在 ios7 中使用 KeyBoardShrinksView = false,window.height 保持不变.不过,这与 ios6 正好相反,所以有点赶上 22.

I found that with KeyBoardShrinksView = false in ios7, window.height stayed constant. This was the opposite of ios6 though, so a bit of a catch 22.

不确定在 Phonegap 中是否有更好的方法来处理这个问题,但我把它放在 CDVViewController.m 中,为 ios < 创建 config.xml 文件.v7 和 ios > v6,我的应用程序按照我想要的方式工作.看起来有点老套,但对我的其余代码没有太大的破坏.

Not sure if there's a better way of handling this in Phonegap, but I put this in CDVViewController.m, created to config.xml files for ios < v7 and ios > v6, and my app works the way I want. Seemed a bit hacky, but not too disruptive of the rest of my code.

// 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"];
}

(我还在 https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ApplicationPreferences 但不要认为这是为这种偏好而设计的.)

(I also tried an app preference plugin at https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ApplicationPreferences but don't think this was designed for this kind of preference.)

这篇关于Phonegap:键盘在 iOS 7 中更改窗口高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆