2012-01-27 12 views
2

私のUIKeyboardにサブビューを追加するのに少し問題があります。キーボードの位置を確認してuiimageviewを追加することはできますが、残念ながら画像ビューの下にあるボタンにはまだ触れることができます。私はそれを色のオーバーレイにして、不必要なキーを隠して、それらに触れさせないようにしたいと思っています:)UIImageViewをUIKeyboardのサブビューとして追加する - userInteractionEnabled?

ここに私のコードは何ですか? 、UIImageViewを正しく表示しますが、ボタンはまだタップすることができます... :(

- (UIView *)findKeyboard { 

    // Locate non-UIWindow. 
    UIWindow *keyboardWindow = nil; 
    for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) { 
     if (![[testWindow class] isEqual:[UIWindow class]]) { 
      keyboardWindow = testWindow; 
      break; 
     } 
    } 

    // Locate UIKeyboard. 
    UIView *foundKeyboard = nil; 
    for (UIView __strong *possibleKeyboard in [keyboardWindow subviews]) { 

     // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView. 
     if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) { 
      possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0]; 
     }                     

     if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) { 
      foundKeyboard = possibleKeyboard; 
      break; 
     } 
    } 
    return foundKeyboard; 
} 

- (void)keyboardWillShow:(NSNotification *)note { 

    UIImageView *overlayView; 
    UIView *keyboardView = [self findKeyboard]; 
    UIImage *img = [UIImage imageNamed:@"keyboardOverlay.png"]; 
    overlayView = [[UIImageView alloc] initWithImage:img]; 
    [overlayView setUserInteractionEnabled:NO]; 
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, overlayView.frame.size.width, overlayView.frame.size.height)]; 
    newView.userInteractionEnabled = NO; 
    newView.multipleTouchEnabled = NO; 
    [newView addSubview:overlayView]; 
    [keyboardView insertSubview:newView atIndex:40]; 

} 

答えて

2

ユーザーの操作が無効にタッチがまっすぐに通過していることを意味している。それを有効にしますが、任意のジェスチャーrecognisersやアクションを持っていません

+0

ああ、私は本当に愚かです。私はそれについて完全に忘れました...ありがとう本当にありがとう:) –