How do I install this script into PhoneGap for iOS(如何将此脚本安装到 iOS 的 PhoneGap 中)
问题描述
我不懂任何 Objective-C,这就是我使用 PhoneGap 创建 iOS 应用程序的原因.iOS 版 PhoneGap 有一个很大的缺陷.键盘经常有表单助手(下一个"、上一个"和完成"按钮.)网上关于如何摆脱这个的信息很少,所有关于它的 Stackoverflow 问题都说它实际上是不可能的.但过了一会儿,我偶然发现了这个教程.底部段落告诉你如何去做.它工作正常,我下载并测试了完成的应用程序.
I don't know any Objective-C, that is why I'm using PhoneGap to create an iOS app. There is a big flaw in PhoneGap for iOS. The keyboard constantly has the form assistant (the 'next', 'previous' and 'done' buttons.) There is very little information on the web on how to get rid of this, all of the Stackoverflow questions about it said it was practically impossible. But after a while I stumbled upon this tutorial. The bottom paragraph tells you how to do it. And it works, I downloaded and tested the finished app.
但由于我几乎不知道如何在 Xcode 或 Objective-C 中做任何事情,所以我不知道这两段代码进入什么文件,他在教程中没有说.
But since I have no idea how to do almost anything in Xcode, or in Objective-C, I have no idea what files the two sections of code go into, he doesn't say in the tutorial.
谁能告诉我它在 PhoneGap 应用程序文件中的哪个位置?非常感谢,这一直困扰着我一整天.
Can anyone tell me where in the PhoneGap apps files it goes? I'd appreciate it massively, this has been bugging me all day.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
还有这个
RichTextEditorViewController *viewController = [[RichTextEditorViewController alloc] initWithNibName:@"RichTextEditorViewController" bundle:nil];
self.viewController = [[UINavigationController alloc] initWithRootViewController:viewController];
还有这个
- (void)removeBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
}
}
}
}
}
谢谢!
推荐答案
我遇到了自己做这个的需要.我是一名 IOS 开发人员,但需要使用 phonegap 来降低多平台开发的成本.
I have come across the need to do this myself. I am an IOS developer, but needed to use phonegap to keep costs down for multiplatform dev.
无论如何,我修复了您的代码.因为,我想,你不想花时间学习 obj-c,你只需要将 MainViewController.m 的内容替换为以下内容:
Anyway, i fixed your code. As, i guess, you dont want to spend your time learning obj-c, you just need to replace the contents of your MainViewController.m with the following:
#import "MainViewController.h"
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (void) removeBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
}
}
}
}
}
- (void)keyboardWillShow:(NSNotification*) notification {
// remove the bar in the next runloop (not actually created at this point)
[self performSelector:@selector(removeBar) withObject:nil afterDelay:0];
}
@end
作为警告,这是一个有点笨拙的解决方案(但使用 phonegap 也是如此!),并且可能会在未来的 iOS 版本中中断.但我想我们会解决这个问题......
As a word of warning, this is a bit of a hacky solution (but then so is using phonegap!), and may break in future versions of iOS. But i guess we fix that when it comes to it...
这篇关于如何将此脚本安装到 iOS 的 PhoneGap 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将此脚本安装到 iOS 的 PhoneGap 中
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01