问题
I'm searching a way to add a button into the accessory view of a keyboard, the one that comes up when touching an input field into a UIWebView, without using some private functions or some questionable tricks.
Do you know how I may do this ?
Note : I know how I may catch the keyboard show/hide events. What I'm asking for is how to add the button.
回答1:
You can do this using UIKeyboardWillShowNotification
look into UIWindow reference for information about it :
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
This notification is raised when a textfield even from a UIWebView
is selected.
Look at Apple KeyboardAccessory Sample code which shows how to do this. That sample code use the UITextXxxx inputAccessoryView
property, that I doubt you will be able to use. But the notification will give you enough information to add your accessory directly in your view or even on top UIWindow, and that even by animating it with the keyboard :
(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}}";
}}
回答2:
UIKit allows applications to substitute custom input views for the system keyboard. It also enables applications to have an accessory view above the system keyboard or custom input view. Additionally, it enables applications to play key-click sounds when users tap on a controls of an input view or input accessory view.
Refer here for more
回答3:
Take a look at this apple example, as it does exactly what you are searching for. But in general the idea is to replace the inputAccessoryView for the UIWebView
in order to show your custom view.
来源:https://stackoverflow.com/questions/5824325/iphone-adding-a-button-to-keyboard-existing-accessory-view-keyboard-from-uiwe