如何检查iOS中的键盘是否显示字典或单词建议(我不知道正确的术语)。
我在网上搜索但我找不到答案。 在这些单词建议/字典后面是我的输入字段,但是当单词建议/字典存在时,它被隐藏在它后面。我希望我的输入在它们出现时动态地放在单词建议/字典的顶部。要做到这一点,我只需要在出现单词建议/字典时发出通知。有谁知道怎么样?
答案 0 :(得分:1)
我也不知道建议栏的内容......
但您可以使用NSNotificationCenter观察键盘调整大小通知
试试吧。
也许帮助〜
- (void)viewDidLoad {
[super viewDidLoad];
//add UIKeyboardWillShowNotification to NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardShow:)
name:UIKeyboardWillShowNotification
object:nil];
}
- (void)keyboardShow:(NSNotification *)notification{
//Should Log when keyboard show or resize
NSLog(@"keyboard notification");
NSDictionary *userInfo = [notification userInfo];
//Get the keyboard
NSValue *keyBoardValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
//Get the keyboard Rect
CGRect keyboardRect = [keyBoardValue CGRectValue];
NSLog(@"%@",[NSValue valueWithCGRect:keyboardRect]);
}
然后当您操作键盘时
你应该看起来像......keyboard notification
NSRect: {{0, 228}, {320, 252}}
keyboard notification
NSRect: {{0, 264}, {320, 216}}
keyboard notification
NSRect: {{0, 228}, {320, 252}}
keyboard notification
NSRect: {{0, 264}, {320, 216}}
keyboard notification
NSRect: {{0, 228}, {320, 252}}
答案 1 :(得分:1)
为UIKeyboardDidChangeFrameNotification添加观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
在keyboardDidChangeFrame中检索UIKeyboardFrameEndUserInfoKey的值,如果显示的建议你将得到258的高度,否则225
- (void)keyboardDidChangeFrame:(NSNotification*)notification{
NSDictionary *keyboardInfo = [notification userInfo];
CGRect keyboardFrame = [[keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = CGRectGetHeight(keyboardFrame);
NSLog(@"%f", keyboardHeight);
}