如何像 Safari 一样在键盘上方创建 Previous/Next 按钮

How to create Previous/Next buttons above keyboard like in Safari

我正在尝试在键盘上方添加 Previous/Next 按钮,就像在移动版 Safari 中一样。 Whosebug 上有很多关于此的问题,但大多数答案都是使用 inputAccessoryView。 我试过了,它看起来像这样:

下面的工具栏中是否有按钮,就像它在移动 Safari 中一样?

这是它在 Safari 中的样子:

看来我要找的是inputAssistantItem

它允许您在键盘的快捷栏中添加和更改按钮。

UIBarButtonItem* nextButton = [[UIBarButtonItem alloc]
                               initWithImage:nextImage
                               style:UIBarButtonItemStylePlain
                               target:self
                               action:@selector(nextField:)];
UIBarButtonItem* previousButton = [[UIBarButtonItem alloc]
                                   initWithImage:previousImage
                                   style:UIBarButtonItemStylePlain
                                   target:self
                                   action:@selector(previousField:)];
NSArray *buttonGroups = @[[[UIBarButtonItemGroup alloc]
                           initWithBarButtonItems:@[previousButton, nextButton]
                           representativeItem:nil]];

textField.inputAssistantItem.trailingBarButtonGroups = buttonGroups;
UIBarButtonItem *previous = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:103  target:self action:@selector(previousButtonTapped:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:6.0];
UIBarButtonItem *next = [[UIBarButtonItem alloc]  initWithBarButtonSystemItem:104 target:self action:@selector(nextButtonTapped:)];