您可以使用UIKeyboardWillShowNotification 执行此操作,查看UIWindow reference 以获取相关信息:
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
This notification is raised when a textfield even from a UIWebView is selected.
查看 Apple KeyboardAccessory 示例代码,其中显示了如何执行此操作。该示例代码使用 UITextXxxx inputAccessoryView 属性,我怀疑您将能够使用它。但是通知会为您提供足够的信息,让您可以直接在视图中甚至在 UIWindow 顶部添加您的配件,甚至可以通过键盘对其进行动画处理:
(gdb) po notification
NSConcreteNotification 0xb5a2190 {name = UIKeyboardWillShowNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 0;
UIKeyboardAnimationDurationUserInfoKey = "0.300000011920929";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 260}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 610}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 350}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 260}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 220}, {320, 260}}";
}}