@@ -316,23 +316,33 @@ - (void)singleTap:(UITapGestureRecognizer *)sender
316
316
317
317
#pragma mark - notification
318
318
319
- - (void )keyboardWillShow : (NSNotification *)notification {
319
+ - (void )keyboardWillShow : (NSNotification *)notification
320
+ {
320
321
CGRect keyboardRect = [[[notification userInfo ] objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue ];
321
322
322
323
CGFloat alertViewBottomEdge = (CGRectGetHeight (self.view .frame ) - CGRectGetHeight (_alertView.frame ))/2 - _alertViewCenterYOffset;
324
+
325
+ // 当开启热点时,向下偏移20px
326
+ // 修复键盘遮挡问题
327
+ CGFloat statusBarHeight = [UIApplication sharedApplication ].statusBarFrame .size .height ;
323
328
CGFloat differ = CGRectGetHeight (keyboardRect) - alertViewBottomEdge;
329
+
330
+ // 修复:输入框获取焦点时,会重复刷新,导致输入框文章偏移一下
331
+ if (_alertViewCenterYConstraint.constant == -differ -statusBarHeight) {
332
+ return ;
333
+ }
324
334
325
335
if (differ >= 0 ) {
326
- _alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ;
336
+ _alertViewCenterYConstraint.constant = _alertViewCenterYOffset - differ - statusBarHeight ;
327
337
[UIView animateWithDuration: 0.25 animations: ^{
328
338
[self .view layoutIfNeeded ];
329
339
}];
330
340
}
331
341
}
332
342
333
343
334
- - (void )keyboardWillHide : (NSNotification *)notification {
335
-
344
+ - (void )keyboardWillHide : (NSNotification *)notification
345
+ {
336
346
_alertViewCenterYConstraint.constant = _alertViewCenterYOffset;
337
347
[UIView animateWithDuration: 0.25 animations: ^{
338
348
[self .view layoutIfNeeded ];
@@ -348,7 +358,6 @@ - (void)dealloc
348
358
{
349
359
[[NSNotificationCenter defaultCenter ] removeObserver: self name: UIKeyboardWillShowNotification object: nil ];
350
360
[[NSNotificationCenter defaultCenter ] removeObserver: self name: UIKeyboardWillHideNotification object: nil ];
351
- // NSLog(@"%@ dealloc",NSStringFromClass([self class]));
352
361
}
353
362
354
363
@end
0 commit comments