2012-01-27 45 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

用户交互被禁止,意味着触摸笔直地穿过。启用它,但没有任何手势识别器或行动,它会吞噬所有的触动

+0

噢,我真的很笨,我完全忘了那个......非常感谢你:) – 2012-01-27 16:35:25

相关问题