第三方键盘高度

来源:互联网 发布:java svn使用教程 编辑:程序博客网 时间:2024/05/07 17:45
//第三方键盘,监听UIKeyboardWillShowNotification时,会触发三次,如果在这个监听事件中拿键盘的高度,第一次拿到的是0,第二次是系统键盘高度,第三次是真正的高度//例://添加监听- (void)addObserverEvent {    self.keyboardHeight = 216;    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHiden) name:UIKeyboardWillHideNotification object:nil];}//键盘即将出现- (void)keyboardWillShow:(NSNotification *)notifition {    NSDictionary *userInfo = notifition.userInfo;    self.keyboardHeight = [[userInfo objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;    objc_setAssociatedObject(self.class, &kIsGetKeyBoardHeight, [NSNumber numberWithFloat:self.keyboardHeight], OBJC_ASSOCIATION_RETAIN_NONATOMIC);//将得到的高度绑定到类上,程序退出之前都可以不监听了}//键盘已经出现。。。处理第三方键盘在要跟随键盘的view做动画效果之前还没有拿到真正的高度- (void)keyboardDidShow:(NSNotification *)notifition {    NSDictionary *userInfo = notifition.userInfo;    self.keyboardHeight = [[userInfo objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;    objc_setAssociatedObject(self.class, &kIsGetKeyBoardHeight, [NSNumber numberWithFloat:self.keyboardHeight], OBJC_ASSOCIATION_RETAIN_NONATOMIC);    [self showAnimation];}//键盘消失,移除监听- (void)keyboardWillHiden {    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];}//第三方键盘有键盘消失按钮!!!键盘消失之后,再点击界面键盘重新出现- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {    if (![_passWord isFirstResponder]) [_passWord becomeFirstResponder];}
0 0
原创粉丝点击