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

查看:260
本文介绍了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.

在键盘打开之前窗口的高度是568根据$(窗口).height()和它被打开后,它被关闭后它是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.

推荐答案

我也看到了。

我发现在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天全站免登陆