2012-03-06 18 views
8

私はObjective-Cを初めて使っています。ユーザーが通常のキーボードのアルファベット部分から数値/句読点に切り替えるのを制限しようとしています。これは、私はスイッチを行うキーボード上のボタンを無効にしたいと言われています。たぶん私は間違った検索パラメータを入れているかもしれませんが、私はGoogleでほとんど見つけられていません。実際にiOSキーボードのボタンを無効にするにはどうすればいいですか?アルファベット/数字/句読点文字では、これは入力された入力文字を無視するだけで簡単に行えますが、キーボード部分を切り替えるボタンは文字を返すのではなくアクションを行います。キーボードのキーを無効にする

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

答えて

4

あなたが実際にこのようなインターネット上のいくつかのレシピがありますUIKeyboard

デフォルトのボタンを追加および削除することができます:http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.htmlと、このような:http://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html

は、これらの記事は、しかし、ボタンを追加する方法をお見せ同じ原則を用いて除去することができる。

以下

私はあなたの解決策の一つのコンパイルを紹介します:

//The UIWindow that contains the keyboard view - 
//It some situations it will be better to actually 
//iterate through each window to figure out where the keyboard is, 
// but In my applications case 
//I know that the second window has the keyboard so I just reference it directly 
// 
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] 
//      objectAtIndex:1]; 

//Because we cant get access to the UIKeyboard throught the SDK we will 
// just use UIView. 
//UIKeyboard is a subclass of UIView anyways 
UIView* keyboard; 

//Iterate though each view inside of the selected Window 
for(int i = 0; i < [tempWindow.subviews count]; i++) 
{ 
    //Get a reference of the current view 
    keyboard = [tempWindow.subviews objectAtIndex:i]; 

    //Check to see if the className of the view we have 
    //referenced is "UIKeyboard" if so then we found 
    //the keyboard view that we were looking for 
    if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
    { 
     // Keyboard is now a UIView reference to the 
     // UIKeyboard we want. From here we can add a subview 
     // to th keyboard like a new button 

     //Do what ever you want to do to your keyboard here... 
    } 
} 
+0

ありがとうございました!私はそれを見なければならないでしょう。 JavaとC/C++のバックグラウンドからくるObjective-Cのやり方は時にはちょっと変わってくることがあります。 – alownx

1

私はすっきりソリューションを実装しました。そのトリックは、無効なキーイメージをキーボードの上に置くことです。

この

  1. 実行エミュレータを実行するには、画面あなたが好きな資産をつかむ(100%スケールで)
  2. (私の場合、これは下の右端の無効完了ボタンがありました)キーボードは別々のUIWindow(iOS5をするので、私は信じている)に配置されるため、次の

    + (void) addSubviewToTop:(UIView *)view { 
        int count = [[[UIApplication sharedApplication] windows] count]; 
        if(count <= 0) { 
         warn(@"addSubviewToTop failed to access application windows"); 
        } 
        UIWindow *top_window = [[[UIApplication sharedApplication] windows] objectAtIndex:count-1]; 
        [top_window addSubview:view]; 
        [top_window bringSubviewToFront:view]; 
    } 
    
    を行う必要がありますことを、キーボード

ノートの上にこの画像を配置

0

@ ppaulojrの答えが機能しなくなったようなSDKが変更されたのか、私のシステムで奇妙なことが起こったのか分かりませんが、以下の調整ができました。

@ ppaulojrの回答にリンクされている投稿は素晴らしいです(http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.htmlhttp://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html)。これは私に役立ちました。

明らかに実際のキーボードビューは、より壮大なUIKeyboardビュー構造でサブビューとして埋め込まれているため、少しの再帰が含まれているようです。私もこの関数を呼び出すのに最適な場所は-(void)textViewDidBeginEditing:(UITextView *)textViewからとても似ていることがわかっ

-(void) findKeyboard { 

    NSArray* windows = [[UIApplication sharedApplication] windows]; 

    for (int i = 0; i < [windows count]; i++) { 

     UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] 
                  objectAtIndex:i]; 

     for(UIView *subView in [tempWindow subviews]) 
     { 
      [self checkViews:subView]; 
     } 
    } 
} 

-(void)checkViews:(UIView *)inView 
{ 
    for(UIView *keyboard in inView.subviews) 
    { 
     NSLog(@"ViewName: %@", [keyboard description]); // Which view are we looking at 

     //Check to see if the className of the view we have 
     //referenced is "UIKeyboard" if so then we found 
     //the keyboard view that we were looking for 
     if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
     { 
      // Keyboard is now a UIView reference to the 
      // UIKeyboard we want. From here we can add a subview 
      // to th keyboard like a new button 

      //Do what ever you want to do to your keyboard here... 


      break; 
     } 

     // Recurse if not found 
     [self checkViews:subView]; 
    }  
} 

:私はこれが動作するようになった。これは、すぐにキーボードが追加されると、キーボードの変更を行います

- (void)textViewDidBeginEditing:(UITextView *)textView { 
    NSLog(@"textViewDidBeginEditing"); 

    [self findKeyboard]; 

} 

ウィンドウが表示されますが、実際に表示される前に、下から上がるまでの時間が変更されます。

関連する問題