2012-01-03 2 views
6

私はObjective-Cを知らないので、PhoneGapを使ってiOSアプリケーションを作成しています。 iOSのPhoneGapには大きな欠陥があります。キーボードにはフォームアシスタント( 'next'、 'previous'、 'done'ボタンなど)が常にあります。これについての情報はほとんどありません。不可能。しかし、しばらくして、私はこのチュートリアルを見つけました。一番下の段落は、それを行う方法を説明しています。それが動作し、私はダウンロードし、完成したアプリをテストしました。iOS用のPhoneGapにこのスクリプトをインストールするには

しかし、私はXcodeやObjective-Cで何ができるのかわからないので、コードの2つのセクションがどのファイルに入っているのか分かりません。チュートリアルでは言いません。

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

ありがとうございました!

+2

Wordを追加します。 obj-cを学ぶと、もっと幸せになれます。 –

答えて

16

私はこれを自分で行う必要性を抱いています。私はIOSの開発者ですが、マルチプラットフォーム開発のコストを抑えるためにphonegapを使用する必要がありました。

とにかく、コードを修正しました。私が推測する、として、あなたがobj-Cを学ぶあなたの時間を過ごしたいいけない、あなただけの次にあなたの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. 
    // 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で壊れるかもしれない。しかし、私はそれがそれになるとそれを修正すると思います...

+0

ありがとうございました! –

+0

おい、ありがとう! あなたの答えが私の以前のグーグルでは上がらなかったことに驚いています。 この回答は間違いなくより多くのupvotesに値する方法です。 – hasen

+0

これを試した後、ちょっとした問題に遭遇しました。これは黒いバーを表示から削除しますが、バーは「まだそこに」あります。これは、webviewのスクロール方法に影響します。意味は、入力フィールドがそのバーの後ろにある場合、システムはビューをスクロールアップさせます。 – hasen

0

キーボードのコントロールを強化するためにいくつかのPhoneGapプラグインがあります。私はこれをまだ使用していませんが、あなたがしようとしていることをIonic Keyboard Pluginが提供するように見えます。

「次、前の、完了したボタンでキーボードアクセサリバーを非表示にする」 方法:cordova.plugins.Keyboard.hideKeyboardAccessoryBar

は、それを追加するには:コルドバプラグイン はアドバイスのhttps://github.com/driftyco/ionic-plugins-keyboard.git

関連する問題