保持iPhone键盘对齐工具栏通过第一个响应的变化可见? [英] Keep iPhone keyboard-aligned toolbar visible through first responder change?

查看:109
本文介绍了保持iPhone键盘对齐工具栏通过第一个响应的变化可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是由Josh在<一个描述的方法href=\"http://stackoverflow.com/questions/158574/programatically-align-a-toolbar-on-top-of-the-iphone-keyboard\">this问题到工具栏添加到iPhone键盘的顶部。基本上,这个想法是:

I'm using the method described by Josh in this question to add a toolbar to the top of the iPhone's keyboard. Basically, the idea is:


  • 添加视图控制器作为通知的观察者 UIKeyboardWillShowNotification UIKeyboardWillHideNotification 在其初始化方法

  • 当这些通知张贴,用键盘以及动画工具栏上/关闭屏幕

  • Add the view controller as an observer for the notifications UIKeyboardWillShowNotification and UIKeyboardWillHideNotification in its initialization method
  • Whenever those notifications are posted, animate a toolbar onto/off of the screen along with the keyboard

我也有在屏幕上多UITextFields,选择编辑时和编辑时辞职第一响应完成(无论是用户点击另一个文本字段,关闭任何文本字段,或者presses所有这一切都成为第一个响应完成键盘上的 - 我有 textFieldShouldReturn:覆盖到 resignFirstResponder

I also have multiple UITextFields on the screen, all of which become the first responder when selected for editing and resign first responder when editing is complete (either the user taps another text field, off any text field, or presses "Done" on the keyboard - I have textFieldShouldReturn: overridden to resignFirstResponder).

我有一个问题,虽然,因为通知被张贴我每次文本字段之间进行切换。例如,如果用户正在编辑文本字段A,然后用它完成和水龙头文本字段B,A辞职第一响应和B成为第一个响应者。然而,这也张贴无论是会显示和将隐藏通知我视图控制器。

I'm having a problem, though, since the notifications are being posted every time I switch between text fields. For example, if a user is editing text field A, then finishes with it and taps text field B, A resigns first responder and B becomes first responder. However, this also posts both the "will show" and "will hide" notifications to my view controller.

所有这一切的最终结果是,当工具栏显示与键盘的第一个文本字段,并用键盘在最后文本字段消失,这似乎每次用户滑入和背出键盘的文本字段之间切换。

The end result of all this is that while the toolbar appears with the keyboard for the first text field, and disappears with the keyboard for the last text field, it appears to slide into and back out of the keyboard every time the user switches between text fields.

有没有一种方法,如果键盘是只给将{显示,隐藏}通知作出回应的实际要显示或隐藏?换句话说,我怎么能无视通知,不会导致键盘的可见状态的改变?

Is there a way to only respond to the "will {show,hide}" notifications if the keyboard is actually going to show or hide? Put another way, how can I ignore notifications that will not result in a change in the keyboard's visible state?

推荐答案

您需要做一个BOOL伊娃来跟踪键盘是否已经可见,所以你会很好地利用所有的UITextField代表的方法:)工具栏与多个文本字段可能会非常棘手,但你非常接近!

You need to make a BOOL ivar to keep track of whether or not the keyboard is already visible, so you'll make good use of all of the UITextField delegate methods :) Toolbars with multiple text fields can be tricky, but you're very close!

这篇关于保持iPhone键盘对齐工具栏通过第一个响应的变化可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆