简体   繁体   English

跨多个视图的自定义键盘

[英]Custom Keyboard across multiple views

I have a UIViewController with a UITextField that uses a custom 'DONE' button when the keyboardType is set to NumberPad. 我有一个带有UITextField的UIViewController,当keyboardType设置为NumberPad时,该UITextField使用自定义的“ DONE”按钮。 I've used code similar to this - 我使用了与此类似的代码-

http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key

However, My problem is that the custom keyboard remains everywhere in other UIviews of application. 但是,我的问题是,自定义键盘仍然保留在应用程序的其他UIview中的任何位置。 If I call the keyboard from another View Controller I still get the 'DONE' button overlaying the keyboard. 如果我从另一个View Controller调用键盘,我仍然会在键盘上看到“ DONE”按钮。 I have other views that need Uncustomized versions of the UIKeyboard. 我还有其他需要UIKeyboard的非自定义版本的视图。

Thanks 谢谢

I started with the exact same blog as you mentioned above. 我从与您上面提到的博客完全相同的博客开始。 I ran into the same exact issue because I had multiple keyboard types throughout my application. 我遇到了同样的问题,因为我在整个应用程序中都有多种键盘类型。

My solution included these changes: 我的解决方案包括以下更改:

1 - Make the UIButton *doneButton a member variable for the Controller class 1-使UIButton * doneButton成为Controller类的成员变量

2 - In the "viewDidLoad" method, I have the following snippet 2-在“ viewDidLoad”方法中,我有以下代码段

self.doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

3 - In the "doneButton" IBAction, I have the following snippet to make sure the button is removed from the keyboard view. 3-在“ doneButton” IBAction中,我有以下代码片段来确保从键盘视图中删除该按钮。

- (IBAction) doneButton:(id)sender {
    [self.view endEditing:YES];
    [doneButton removeFromSuperview];
}

The logic to add the button is no different than the blog describes so as long as you follow that direction, you should see the button on your number keyboard, then see it removed when you click the "DONE" button. 添加按钮的逻辑与博客描述的相同,因此只要您遵循该方向,就应该在数字键盘上看到该按钮,然后在单击“完成”按钮时将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM