gpt4 book ai didi

iphone - 从 Nib 加载的 View 未获取触摸事件

转载 作者:行者123 更新时间:2023-11-28 19:11:01 25 4
gpt4 key购买 nike

我使用一些按钮创建了一个自定义键盘。我使用界面生成器创建了它们,并创建了一个 CustomKeyboardView 文件..

所以我有3个文件

  1. 自定义键盘 View .h
  2. 自定义键盘 View .m
  3. 自定义键盘 View .xib

我正在像这样将此 View 添加到我的 UIViewController

-(void)createCustomKeyboard{
//kbdCustom is an instance of CustomKeyboardView
kbdCustom = [[[NSBundle mainBundle] loadNibNamed:@"CustomKeyBoardView"
owner:self options:nil] objectAtIndex:0];
kbdCustom.delegate = self;
CGRect frame = kbdCustom.frame;
frame.origin.x = 14.0;
frame.origin.y = 300.0;
kbdCustom.frame = frame;
kbdCustom.backgroundColor = [UIColor clearColor];
[self.view addSubview:kbdCustom];
[self.view bringSubviewToFront:kbdCustom];
}

我在屏幕上看到自定义键盘。但是我无法触摸任何按钮。

CustomKeyBoardView.m 文件中没有什么特别的。我有一些按钮处理程序来处理键盘中每种不同类型的按钮。

自定义键盘 View .m

@implementation CustomKeyBoardView
- (IBAction)numberPressed:(id)sender {
NSLog(@"Number pressed");
}

- (IBAction)specialCharsPressed:(id)sender {
NSLog(@"specialCharsPressed");
}

- (IBAction)clearTextPressed:(id)sender {
NSLog(@"clearTextPressed");
}

- (IBAction)enterButtonPressed:(id)sender {
NSLog(@"enterButtonPressed");
}
@end

其他一些可能对你(帮助我)有帮助的点

  1. 我检查并重新检查了按钮处理程序。他们被连接到IBAction.
  2. 我以编程方式在键盘上添加了一个按钮(由覆盖 CustomKeyboardView.m 中的 awakeFromNib 函数)和这个当我将它添加到 UIViewController 时,按钮也会显示。但不是该按钮上的 userInteraction 也是如此。
  3. 有问题的 UIViewController 显示在UIPopOverController。我们在项目中使用 Storyboard。
  4. 我已经添加了一些日志来查看用户交互是否正常在 kbdCustom 及其 super View 中启用。答案在肯定的

    NSLog(@"kbdCustom.userInteractionEnabled : %d"
    , kbdCustom.userInteractionEnabled);
    NSLog(@"superView.userInteractionEnabled : %d"
    , kbdCustom.superView.userInteractionEnabled);

    它的输出是

    kbdCustom.userInteractionEnabled : 1
    superView.userInteractionEnabled : 1
  5. 当然,所有按钮上的用户交互都是YES,而且所有它们中的一部分在界面构建器中启用。

  6. 我已经调整了键盘的框架,将其向上移动到UITextField(正确接收触摸事件)。现在当我单击键盘按钮,它下面的 UITextField 正在获取触摸,好像键盘不在那里。

最佳答案

检查 View 的自动调整大小,并设置它的层 clipsToBound,然后查看它是否仍然可见。如果不是,则意味着您的 View 由于 autoSizing 而缩小到最小尺寸,但它的 subview 显示在您的 baseView 的边界之外。在这种情况下,您可以看到它们但无法触摸。

关于iphone - 从 Nib 加载的 View 未获取触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com