复制代码
  1. [[NSNotificationCenter defaultCenter] addObserver:self
  2.                                              selector:@selector(keyboardWillShow:)
  3.                                                  name:UIKeyboardWillShowNotification
  4.                                                object:nil];


核心思路代码:
复制代码

  1. - (void)keyboardWillShow:(NSNotification *)note
  2. {  
  3.     UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];//知识点
  4.     for(int i=0; i<[tempWindow.subviews count]; i++)
  5.     {
  6.         keyboard = [tempWindow.subviews objectAtIndex:i];
  7.         if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
  8.         {
  9.             [keyboard setFrame:CGRectMake(0, 460, 320, 345)];
  10.             [self congfigKeypad];
  11.             
  12.             [keyboard addSubview:keyPadView1];
  13.             
  14.         }
  15.     }
  16. }


比如配置方法可以是这样:
复制代码
  1. -(void)congfigKeypad
  2. {
  3.    SearBtn *one = [[SearBtn alloc] initWithFrame:CGRectMake(81, 3, kNumPadW, kNumPadH) index:1 ContextString:@"1" type:kNumPadType];
  4.     [one setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
  5.     [one addTarget:self action:@selector(buttonClickAtIndex:) forControlEvents:UIControlEventTouchUpInside];
  6.         //......略
  7. }


添加NSMutalbeString作为文本域字串的容器,点击button后append的button对应的字串。
复制代码

  1. - (void)buttonClickAtIndex:(id)sender
  2. {
  3.     SearBtn *btnItem = (SearBtn*)sender;
  4.     NSString *str = btnItem->btnText;
  5.     [s_text appendString:str];
  6.     [sBar setText:s_text];
  7. }
;

再实现一个deleteChar的方法作为退格键
思路:
复制代码
  1. if ([s_text length] > 0)
  2.     {
  3.         NSRange rang;
  4.         rang.location = [s_text length] - 1;
  5.         rang.length = 1;
  6.         [s_text deleteCharactersInRange:rang];
  7.     }


现在点击各种文本域,应该就可以现实自己的键盘了。

继续优化
用textfield的代理方法控制键盘的字串类型,长度,和响应消失

 

http://www.cocoachina.com/bbs/read.php?tid-12429.html 

相关文章:

  • 2022-01-08
  • 2021-07-16
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-08-01
  • 2021-11-01
猜你喜欢
  • 2021-09-21
  • 2021-12-04
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案