我想获得指向UIKeyboard *keyboard
的指针引用到屏幕上的键盘,以便可以向其添加透明的 subview ,以完全覆盖它,以达到disabling the UIKeyboard
without hiding it的效果。
为此,我可以假设一次屏幕上只有一个UIKeyboard
吗?即是一个单例吗?方法[UIKeyboard sharedInstance]
在哪里。如果您通过类别实现该方法,布朗尼会指出。或者,如果您说服我,为什么只装一个键盘并给我一个更好的解决方案,这是一个坏主意,那将是更多的布朗尼点。
最佳答案
试试这个:
// my func
- (void) findKeyboard {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIKeyboard.
UIView *foundKeyboard = nil;
for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
}
if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
foundKeyboard = possibleKeyboard;
break;
}
}
}
关于iphone - iOS:如何访问 `UIKeyboard`?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6457239/