简体   繁体   English

如何使用Next,Previous和Done Button键盘?

[英]How to get keyboard with Next, Previous and Done Button?

I want to have a keyboard which has a Next,Previous and Done button on top of it. 我想要一个键盘,它上面有一个Next,Previous和Done按钮。

I have seen that in many apps. 我在许多应用程序中看到过这一点。

Especially where there are forms to be filled. 特别是有形式需要填写的地方。

在此输入图像描述

I want to achieve something similar to above keyboard 我想实现与键盘上面类似的东西

How can I get that? 我怎么能得到它?

You'll find the answer on this other post . 你会在另一篇文章中找到答案。 I checked the iOS Library and the inputAccessoryView of a UITextField is exactly what you're looking for ! 我检查了iOS库,UITextField的inputAccessoryView正是你要找的!

Hope this helps ! 希望这可以帮助 !

I just created a class called BSKeyboardControls which makes it very easy to add the controls to a keyboard. 我刚刚创建了一个名为BSKeyboardControls的类,这使得将控件添加到键盘非常容易。 The class, instructions and example code can be found here at GitHub . 可以在GitHub上找到类,指令和示例代码。

The controls works for text fields and text views and are optimized for both iPhone and iPad. 这些控件适用于文本字段和文本视图,并针对iPhone和iPad进行了优化。

-(BOOL)textFieldShouldBeginEditing: (UITextField *)textField 

{
     UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];

    keyboardToolBar.barStyle = UIBarStyleDefault;
    [keyboardToolBar setItems: [NSArray arrayWithObjects:
                                [[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],

                                [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
                                [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                                [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
                                nil]];
    textField.inputAccessoryView = keyboardToolBar;

}



- (void)nextTextField {


    if (textField1) {

        [textField1 resignFirstResponder];
        [textField2 becomeFirstResponder];

    }

}

-(void)previousTextField
{

    if (textField2) {
        [textField2 resignFirstResponder];
        [textField1 becomeFirstResponder];
    }


}

-(void)resignKeyboard {

    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];

}

I have a utility class that basically does this for you. 我有一个实用程序类,基本上为你做这个。

https://github.com/kalvish21/CustomKeyboard https://github.com/kalvish21/CustomKeyboard

The idea is very simple. 这个想法非常简单。 You have to add an accessory tool bar with bar button items on it. 您必须添加一个带有条形按钮项的附件工具栏。 There's a delegate which defines where what that button will do. 有一个委托,它定义了该按钮的作用。

https://github.com/hackiftekhar/IQKeyboardManager https://github.com/hackiftekhar/IQKeyboardManager

This is the best keyboard handler I have seen so far. 这是迄今为止我见过的最好的键盘处理程序。 Very excellent way to manage Text inputs. 管理文本输入的非常好的方法。

Some of its features 1) ZERO LINE OF CODE 它的一些功能1)ZERO LINE OF CODE

2) Works Automatically 2)自动工作

3) No More UIScrollView 3)没有更多的UIScrollView

4) No More Subclasses 4)没有更多的子类

5) No More Manual Work 5)没有更多的手工工作

6) No More #imports 6)没有#imports

This is a custom control which is placed directly above the keyboard. 这是一个直接放在键盘上方的自定义控件。 I think a UIToolbar can be used for that. 我认为可以使用UIToolbar。

Previous and next passes around the firstResponder of the textFields and Done will do the resign as well as hide the toolbar. 上一个和下一个遍历textFields的第一个响应者,Done将执行resign并隐藏工具栏。

To match the keyboard animation have a look at this code I found or at SO: "What is the iPhone's default keyboard animation rate?" 要匹配键盘动画,请查看我找到的代码或SO: “iPhone的默认键盘动画速率是多少?”

我创建了一个存储库,其中包含此功能的实现,可在所有方向的iPhone / iPad上运行,并且可高度自定义。

As mentioned in other answers, it's the inputAccessoryView that you're looking for. 正如其他答案所述,它是您正在寻找的inputAccessoryView

I would like to add an alternative way here, by using this cocoapods: 我想通过使用这个cocoapods在这里添加另一种方法:

pod ' UITextField-Navigation ' pod'UITextField-Navigation '

All UITextField s will have two additional properties: nextTextField and previousTextField . 所有UITextField都有两个附加属性: nextTextFieldpreviousTextField You can then simply connect the nextTextField in the Interface Builder and the Previous, Next and Done buttons are added automatically for you, all functional, no more code is needed, no subclassing. 然后,您可以简单地在Interface Builder中连接nextTextField ,并自动为您添加Previous,Next和Done按钮,所有功能,不再需要代码,不进行子类化。

You can also customize the UI, add more buttons, etc as you want to. 您还可以根据需要自定义UI,添加更多按钮等。

在此输入图像描述 在此输入图像描述

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

相关问题 UIWebView 中的 iPhone 键盘,如何更改下一个/上一个和完成按钮的语言 - iPhone keyboard in UIWebView, how to change the language of next/previous and done buttons 在html表单中删除“上一个”,“下一个”和“完成”按钮 - Remove 'previous', 'next' and 'done' button at html form iOS 8-UIWebView键盘-上一个/下一个/完成附件栏-如何删除工具栏? - iOS 8 - UIWebView Keyboard - Previous/Next/Done Accessory Bar - How can I remove the toolbar? 如何将完成按钮添加到键盘 - How is a done button added to a keyboard 如何将完成按钮添加到键盘? - How to add Done button to the keyboard? 更改iOS虚拟键盘“previous”,“next”,“done”按钮的语言 - Change the language of iOS virtual keyboard “previous”, “next”, “done” buttons UIWebView键盘 - 摆脱“上一个/下一个/完成”栏 - UIWebView Keyboard - Getting rid of the “Previous/Next/Done” bar 如何使用UITextView显示“上一个/下一个/完成”栏 - How to show the “Previous/Next/Done” bar with a UITextView 你如何摆脱 iPhone 键盘上的 next-prv done 按钮? - How do you get rid of next-prv done buttons on top of iPhone keyboard? 如何在横向模式下将完成的按钮添加到键盘? - How to add a done button to the keyboard in landscape mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM