【问题标题】:Is it possible to add done button inside the keyboard in iphone?是否可以在 iphone 的键盘内添加完成按钮?
【发布时间】:2012-08-31 02:20:13
【问题描述】:

目前我正在使用 iPhone 应用程序,使用 UITextField 输入电话号码,用户输入电话号码,那么如何隐藏键盘?因为这里没有返回按钮,是否可以在键盘内添加完成按钮,请帮助我

提前致谢

【问题讨论】:

  • 听起来您需要滚动自己的屏幕键盘...
  • 我完全明白你的意思,我遇到了同样的问题。但是我最终并没有制作一个新的 OSKB,而是将“完成”按钮绑定在遥控器上未使用的键上。如果您尝试使用后退按钮并覆盖 onBackPressed();,也许您可​​以获得相同的行为
  • 我不明白你的 cmets
  • @Minus:请查看我更新的答案。

标签: iphone keyboard textfield programmatically-created


【解决方案1】:

Here 是一个很好的教程。

【讨论】:

  • 这对于非 ios 开发者来说也很棒。
【解决方案2】:

参考这个link. 它展示了如何在键盘上添加“完成”按钮。

但我建议您改用inputAccessoryView。参考这个SO post

并且必读 this SO answer.

【讨论】:

  • 好建议,但从用户体验的角度来看,它不太方便。
【解决方案3】:

您可以使用“应用”和“取消”按钮添加 inputAccessoryView,然后使用 then 关闭数字键盘。

inputAccessoryView

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    numberToolbar.barStyle = UIBarStyleBlackTranslucent;
    numberToolbar.items = [NSArray arrayWithObjects:
                         [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                         [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                         [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                     nil];
    [numberToolbar sizeToFit];
    numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
    [numberTextField resignFirstResponder];
    numberTextField.text = @"";
}

-(void)doneWithNumberPad{
    NSString *numberFromTheKeyboard = numberTextField.text;
    [numberTextField resignFirstResponder];
}

【讨论】:

    【解决方案4】:

    不使用完成按钮,您也可以通过触摸视图上的任意位置来隐藏数字键盘

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [yourtextfieldname resignFirstResponder];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-20
      • 2014-03-05
      • 2011-02-19
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2016-03-19
      相关资源
      最近更新 更多