【问题标题】:Add UIImageView as a subview to UIKeyboard - userInteractionEnabled?将 UIImageView 作为子视图添加到 UIKeyboard - userInteractionEnabled?
【发布时间】:2012-01-27 16:19:48
【问题描述】:

我在向 UIKeyboard 添加子视图时遇到了一点问题。我可以成功找到我的键盘并为其添加一个uiimageview,但不幸的是仍然可以触摸图像视图下的按钮。我只是想让它成为一个颜色叠加层,这样可以隐藏不需要的键,也让它们不可触摸:)

这是我的代码,我做错了什么? 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];

}

【问题讨论】:

    标签: objective-c ios ipad keyboard uiimageview


    【解决方案1】:

    用户交互被禁用意味着直接通过触摸。启用它,但没有任何手势识别器或动作,它会吞噬所有触摸。

    【讨论】:

    • 哦,我真的很笨。我完全忘记了......非常感谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2018-05-16
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    相关资源
    最近更新 更多