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