IOS键盘监听
键盘消失
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotificationobject:nil];
键盘出现
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasShow:) name:UIKeyboardDidShowNotification object:nil];
所有key值
UIKIT_EXTERNNSString *const UIKeyboardWillShowNotification;
UIKIT_EXTERNNSString *const UIKeyboardDidShowNotification;
UIKIT_EXTERNNSString *const UIKeyboardWillHideNotification;
UIKIT_EXTERNNSString *const UIKeyboardDidHideNotification;
触发方法
- (void)keyboardWillShow:(NSNotification *)notification
{
CGPoint beginCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterBeginUserInfoKey] CGPointValue];
CGPoint endCentre = [[[notification userInfo] valueForKey:UIKeyboardCenterEndUserInfoKey] CGPointValue];
CGRect keyboardBounds = [[[notification userInfo] valueForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
CGRect keyboardFrames = [[[notification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [[[notification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
NSTimeInterval animationDuration = [[[notification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
}
**若有警告可将key值写为@""中
上一篇: TWaver版3D化学元素周期表
下一篇: 半小时带你熟悉Docker镜像的构建方式