From 73da22e0365a7375bc85d2bcac751e081d22c4b0 Mon Sep 17 00:00:00 2001 From: zhoulin <497311172@qq.com> Date: Thu, 17 Nov 2022 03:18:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=AE=E7=9B=98=E9=81=AE?= =?UTF-8?q?=E6=8C=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过判断当前输入框在屏幕上的位置来判断键盘是否遮挡输入框。 --- LSTPopView/Classes/Code/LSTPopView.m | 7 ++++--- LSTPopView/Classes/Code/UIView+LSTPV.h | 2 ++ LSTPopView/Classes/Code/UIView+LSTPV.m | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/LSTPopView/Classes/Code/LSTPopView.m b/LSTPopView/Classes/Code/LSTPopView.m index 6423c7b..fb0c411 100644 --- a/LSTPopView/Classes/Code/LSTPopView.m +++ b/LSTPopView/Classes/Code/LSTPopView.m @@ -1454,15 +1454,16 @@ - (void)keyboardWillShow:(NSNotification *)notification{ self.keyboardWillShowBlock? self.keyboardWillShowBlock():nil; if (!self.isAvoidKeyboard) { return; } - CGFloat customViewMaxY = self.customView.pv_Bottom + self.avoidKeyboardSpace; + UIView *firstResponder = [self.customView findFirstResponder]; + CGFloat firstResponderMaxY = CGRectGetMaxY([firstResponder convertRect:firstResponder.bounds toView:self]) + self.avoidKeyboardSpace; CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]; CGRect keyboardEedFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat keyboardMaxY = keyboardEedFrame.origin.y; self.isAvoidKeyboard = YES; - self.avoidKeyboardOffset = customViewMaxY - keyboardMaxY; + self.avoidKeyboardOffset = firstResponderMaxY - keyboardMaxY; self.keyboardY = keyboardEedFrame.origin.y; //键盘遮挡到弹窗 - if ((keyboardMaxY keyboardMaxY)) { + if (keyboardMaxY *stack = @[self].mutableCopy; + BOOL stop = NO; + UIView *view = nil; + while (stack.count != 0 && !stop) { + if ([stack.lastObject isFirstResponder]) { + stop = YES; + view = stack.lastObject; + break;; + } + if (stack.lastObject.subviews.count != 0) { + [stack insertObjects:stack.lastObject.subviews atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, stack.lastObject.subviews.count)]]; + } + [stack removeLastObject]; + } + return view; +} + + @end