Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions LSTPopView/Classes/Code/LSTPopView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<customViewMaxY) || ((_originFrame.origin.y + _customView.pv_Height) > keyboardMaxY)) {
if (keyboardMaxY<firstResponderMaxY) {
//执行动画
[UIView animateWithDuration:duration animations:^{
self.customView.pv_Y = self.customView.pv_Y - self.avoidKeyboardOffset;
Expand Down
2 changes: 2 additions & 0 deletions LSTPopView/Classes/Code/UIView+LSTPV.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ CGFloat pv_ScreenWidth(void);
/** 屏幕高度 */
CGFloat pv_ScreenHeight(void);

- (UIView *)findFirstResponder;

@end

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions LSTPopView/Classes/Code/UIView+LSTPV.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,23 @@ CGFloat pv_ScreenHeight(void) {
return size.height;
}

- (UIView *)findFirstResponder {
NSMutableArray<UIView *> *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