Skip to content

Commit a8e182d

Browse files
author
费凯峰
committed
1、修复开启热点时键盘遮挡问题
2、修复输入框获取焦点时重复刷新界面问题
1 parent a157743 commit a8e182d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

TYAlertControllerDemo/TYAlertController/TYAlertController.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,33 @@ - (void)singleTap:(UITapGestureRecognizer *)sender
316316

317317
#pragma mark - notification
318318

319-
- (void)keyboardWillShow:(NSNotification*)notification{
319+
- (void)keyboardWillShow:(NSNotification*)notification
320+
{
320321
CGRect keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
321322

322323
CGFloat alertViewBottomEdge = (CGRectGetHeight(self.view.frame) - CGRectGetHeight(_alertView.frame))/2 - _alertViewCenterYOffset;
324+
325+
//当开启热点时,向下偏移20px
326+
//修复键盘遮挡问题
327+
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
323328
CGFloat differ = CGRectGetHeight(keyboardRect) - alertViewBottomEdge;
329+
330+
//修复:输入框获取焦点时,会重复刷新,导致输入框文章偏移一下
331+
if (_alertViewCenterYConstraint.constant == -differ -statusBarHeight) {
332+
return;
333+
}
324334

325335
if (differ >= 0) {
326-
_alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ;
336+
_alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ - statusBarHeight;
327337
[UIView animateWithDuration:0.25 animations:^{
328338
[self.view layoutIfNeeded];
329339
}];
330340
}
331341
}
332342

333343

334-
- (void)keyboardWillHide:(NSNotification*)notification{
335-
344+
- (void)keyboardWillHide:(NSNotification*)notification
345+
{
336346
_alertViewCenterYConstraint.constant = _alertViewCenterYOffset;
337347
[UIView animateWithDuration:0.25 animations:^{
338348
[self.view layoutIfNeeded];
@@ -348,7 +358,6 @@ - (void)dealloc
348358
{
349359
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
350360
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
351-
//NSLog(@"%@ dealloc",NSStringFromClass([self class]));
352361
}
353362

354363
@end

0 commit comments

Comments
 (0)