Phonegap:完全从iPhone键盘上删除黑条 [英] Phonegap: completely removing the black bar from the iPhone keyboard

查看:203
本文介绍了Phonegap:完全从iPhone键盘上删除黑条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Phonegap开发我们的移动应用程序,我们从这里借用代码从键盘上删除黑色下一个/ prev / done栏:

We're using Phonegap to develop our mobile app, and we borrowed code from here to remove the black next/prev/done bar from the keyboard:

a href =http://stackoverflow.com/a/9276023/35364> http://stackoverflow.com/a/9276023/35364

http://stackoverflow.com/a/9276023/35364

这个代码做的是找到一个黑色的条,作为一个UIView对象,并调用'removeFromSuperview'上。

What that code does is it finds the black bar, as a UIView object, and calls 'removeFromSuperview' on it.

我们不熟悉iOS SDK / API。所以,虽然我们可以看看代码,并了解它的工作,我们不能知道它是否正确或如何改善它。

We're not familiar with the iOS SDK/API. So while we can look at the code and get an idea of what it's doing, we can't tell if it's doing it properly, or how to improve it.

我们遇到的具体问题:

我们有一个文本字段用于写入消息,我们手动控制此字段的位置是在键盘的正上方,类似于本机sms应用程序。换句话说,我们把它放在黑条应该是的地方。

We have a text field for writing a message, and we're manually controlling the placement of this field to be exactly above the keyboard, similar to the native sms app. In other words, we're putting it where the black bar was supposed to be.

当我们聚焦/键入消息字段时,系统将视图向上推。看起来这是一种机制,以确保文本字段在用户输入时不会看不见。

When we focus/type in the message field, the system pushes the view up. It seems like this is a mechanism to make sure the text field is not invisible when the user types in it.

这是发生的,即使文本字段

This is happening even though the text field is visible.

我注意到,通过将输入字段放在黑色条正常上方的位置(与其背后相反),视图不会

I noticed that by putting the input field right above where the black bar would normally be (as oppose to behind it), the view doesn't scroll.

因此,似乎系统以某种方式认为黑条仍然存在!

So it seems the system somehow thinks the black bar is still there!

检查:当黑色条未被删除,我们把文本字段放在它上面,我们可以聚焦和键入它,并且视图不会滚动)。

(To double check: when the black bar is not removed, and we put the text field right above it, we can focus and type in it, and the view would not scroll).

所以问题是:

为什么当编辑一个文本字段时,系统是?是因为黑条还没有完全清除?我们需要做些什么来完全删除黑条吗?我们需要强制iOS重新计算键盘的大小吗?或者是什么?

Why does the "system" push the content up when editing a text-field that's place right "behind" where the black bar is supposed to be? Is it because the black bar is not completely removed yet? Do we need to do something to "completely" remove the black bar? Do we need to force iOS to recalculate the size of the keyboard? or what exactly?

这是iOS UIWebView或Phonegap实现的机制(推高视图)。

Is this mechanism (pushing up the view) implemented by iOS's UIWebView, or by Phonegap?

有没有phonegap应用程序解决了这个问题?

Is there any phonegap app that has solved this problem?

推荐答案

替换

[subviewWhichIsPossibleFormView removeFromSuperview];

UIScrollView *webScroll = [webView.subviews lastObject];
CGRect newFrame = webScroll.frame;

float accesssoryHeight = subviewWhichIsPossibleFormView.frame.size.height;
newFrame.size.height += accesssoryHeight;

[subviewWhichIsPossibleFormView removeFromSuperview];
[webScroll setFrame:newFrame];

它会调整内容滚动视图的大小缺少附件空间的大小。它是使用私人API作为其他代码。详细地说,它不是直接使用私有API,但如果苹果决定改变一个视图如何出现(在这种情况下,键盘和WebView),那么它会崩溃。

例如,如果他们重命名 UIWebFormAccessory ,您的代码将不再工作。

it resize the content scroll view for the amount of missing accessory space. It is as far using "private API" as the other code. In detail it isn't using private API directly but if Apple decide to change how a view appears (in this case Keyboard and WebView) then it will crash.
For example if they rename UIWebFormAccessory, your code will not work anymore.

编辑:

在iOS 5.0+ c $ c> webView.scrollView 。因此,您可以将代码拆分为预先iOS 5后备:


on iOS 5.0+ you can call webView.scrollView directly. So you can split the code to have a pre iOS 5 fallback:

UIScrollView *webScroll;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
    webScroll = webView.scrollView;
} else {
    webScroll = [webView.subviews lastObject]; // iOS 2.x (?) - 4.x
    // make sure this code runs appropriate on older SDKs
}

这篇关于Phonegap:完全从iPhone键盘上删除黑条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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