如何将此脚本安装到iOS的PhoneGap中

我不知道任何Objective-C,这就是为什么我使用PhoneGap来创build一个iOS应用程序。 PhoneGap for iOS有一个很大的缺陷。 键盘上不断有forms助手(“下一个”,“上一个”和“完成”button)。网上关于如何摆脱这一点的信息很less,关于它的所有Stackoverflow问题都说实际上不可能。 但过了一段时间,我偶然发现了这个教程。 底部的段落告诉你如何做到这一点。 它的工作原理,我下载并testing完成的应用程序。

但是因为我不知道如何在Xcode或Objective-C中做任何事情,所以我不知道代码的两个部分是什么文件,他没有在教程中说。

谁能告诉我在哪里PhoneGap应用程序文件呢? 我会很感激,这一直在窃听我整天。

[[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来降低多平台开发的成本。

无论如何,我修正了你的代码。 因为我想,你不想花时间学习obj-c,你只需要用下面的代码来replace你的MainViewController.m的内容:

 #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. // eg 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 

作为一个警告的话,这是一个hacky解决scheme(但是那么是使用phonegap!),并可能打破在未来的iOS版本。 但是,我想我们解决它,当涉及到它…

有一些PhoneGap插件来增强对键盘的控制。 虽然我还没有使用它,但它看起来像离子键盘插件可能会提供你想要做的。

“用下一个,上一个和完成button隐藏键盘附件栏。” 方法:cordova.plugins.Keyboard.hideKeyboardAccessoryBar

要添加它:cordova插件添加https://github.com/driftyco/ionic-plugins-keyboard.git