Tencent / QMUI_iOS

QMUI iOS——致力于提高项目 UI 开发效率的解决方案
http://qmuiteam.com/ios
Other
7.08k stars 1.38k forks source link

QMUIModalPresentationViewController hide 时没有正确清空 keyboardHeight #1150

Closed MoLice closed 3 years ago

MoLice commented 3 years ago

Bug 表现 一个复用的 QMUIModalPresentationViewController 在第一次 show 时升起键盘,内部的 keyboardHeight 变量会记录键盘的高度,当 hide 时 keyboardHeight 没有正确重置为 0,导致下一次 show 时就算没有升起键盘,也依然认为当前存在键盘。

截图

如何重现 伪代码如下:

self.modal = QMUIModalPresentationViewController.new;
[textField becomeFirstResponder];
[self.modal show];
...
[self.modal hide];
...
[self.modal show]; // 再次 show 但不要升起键盘,此时可看到 modal 依然按照有键盘的状态来布局

预期的表现 hide 时正确清空 keyboardHeight

其他信息

MoLice commented 3 years ago

bug 原因在于 viewWillDisappear: 里先禁用键盘监听再降下键盘,导致 hide 时无法在 keyboardWillChangeFrame 里清空 keyboardHeight。 现改为 viewWillDisappear: 时不要禁用键盘,而是使用一个标志位屏蔽 updateLayout,使得 keyboardWillChangeFrame 可以正常触发,keyboardHeight 可以正常清零,只是 updateLayout 不会执行而已。

MoLice commented 3 years ago

已发布 4.2.2 修复该问题。