Kri*_*dra 0 iphone user-interaction interface-builder xib ios
我使用一些按钮创建了一个自定义键盘。我使用界面构建器创建了它们,然后创建了一个CustomKeyboardView文件..
所以我有3个文件
我正在将这个视图添加到我的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];
}
Run Code Online (Sandbox Code Playgroud)
我在屏幕上看到自定义键盘。但我无法触摸任何按钮。
CustomKeyBoardView.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
Run Code Online (Sandbox Code Playgroud)
其他一些可能对您有帮助的要点(帮助我)
IBAction.awakeFromNib函数完成CustomKeyboardView.m),当我将它添加到UIViewController. 但该按钮上也没有用户交互。UIViewController问题被示出为
UIPopOverController。我们在我们的项目中使用故事板。我已经添加了一些日志来查看是否在kbdCustom其超级视图中启用了用户交互。答案是肯定的
NSLog(@"kbdCustom.userInteractionEnabled : %d"
, kbdCustom.userInteractionEnabled);
NSLog(@"superView.userInteractionEnabled : %d"
, kbdCustom.superView.userInteractionEnabled);
Run Code Online (Sandbox Code Playgroud)
它的输出是
kbdCustom.userInteractionEnabled : 1
superView.userInteractionEnabled : 1
Run Code Online (Sandbox Code Playgroud)当然,所有按钮上的用户交互都是YES,并且所有这些都在界面构建器中启用。
我已经调整了键盘的框架,将其向上移动到 UITextField(正确接收触摸事件)上。现在,当我单击键盘按钮时,它下方的 UITextField 正在被触摸,就好像键盘不在那里一样。
检查视图的自动调整大小,并设置它的 layer clipsToBound,然后查看它是否仍然可见。如果不是,则意味着您的视图由于 缩小到最小尺寸autoSizing,但它的子视图显示超出了您的baseView. 在这种情况下,您可以看到它们但不能触摸。
| 归档时间: |
|
| 查看次数: |
1987 次 |
| 最近记录: |