Dav*_*son 17
当键盘停靠时,UIKeyboardWillShowNotification会被抬起.如果键盘已拆分或未对接,则不会引发键盘通知.
如果键盘停靠,UIKeyboardWillShowNotification将会引发,以下情况将成立:
[[[notification userInfo] valueForKey:@"UIKeyboardFrameChangedByUserInteraction"] intValue] == 1
Run Code Online (Sandbox Code Playgroud)
如果键盘未对接,UIKeyboardWillHideNotification将被引发,并且上述语句也将为真.
使用这些信息足以让我编写用户界面代码.
注意:这可能违反了Apple的指导方针,我不确定.
这是与iPad分离键盘一起使用的解决方案(最初来自Zeeshan评论中链接的博客)
[[NSNotificationCenter defaultCenter]
addObserverForName:UIKeyboardDidChangeFrameNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * notification)
{
CGRect keyboardEndFrame =
[[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (CGRectIntersectsRect(keyboardEndFrame, screenRect))
{
// Keyboard is visible
}
else
{
// Keyboard is hidden
}
}];
Run Code Online (Sandbox Code Playgroud)
小智 5
UIKeyboardFrameChangedByUserInteraction 当键盘分割时,键不会一直返回1.
以下是完整的用户信息在字典中的键值UIKeyboardDidShowNotification/ UIKeyboardDidHideNotification.
2012-07-11 11:52:44.701 Project[3856:707] keyboardDidShow: {
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 352}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 944}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 592}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{-352, 0}, {352, 1024}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 0}, {352, 1024}}";
}
2012-07-11 11:52:45.675 Project[3856:707] keyboardDidHide: {
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 352}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 592}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 944}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {352, 1024}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{-352, 0}, {352, 1024}}";
}
Run Code Online (Sandbox Code Playgroud)
相反,您可以使用UIKeyboardCenterBeginUserInfoKey或UIKeyboardCenterEndUserInfoKey键在键盘分割时获得通知.
希望这可以帮助!