mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-24 20:00:37 +00:00
docs: 批量博文
This commit is contained in:
27
Chapter1 - iOS/1.23.md
Normal file
27
Chapter1 - iOS/1.23.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# UIScrollView 拖拽滑动时收起键盘
|
||||
|
||||
|
||||
> 当一个页面的 UIScrollView/UITableView 上有输入框时,为了较好的体验,就是当滑动的时候需要回收键盘
|
||||
|
||||
* 最开始的做法是设置 UIScrollView 的代理位当前控制器,监听 scrollViewWillBeginDragging 方法,找到 keyWindow 并且 endEditing
|
||||
|
||||
|
||||
```
|
||||
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
|
||||
[[UIApplication sharedApplication].keyWindow endEditing:YES];
|
||||
}
|
||||
```
|
||||
|
||||
* 之后偶然有幸看到一个 UIScrollView 的属性"keyboardDismissModel"。实现上述需求只需要一行代码
|
||||
|
||||
```
|
||||
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
|
||||
```
|
||||
|
||||
* keyboardDismissMode 有3个枚举值
|
||||
|
||||
* UIScrollViewKeyboardDismissModeNone:默认值,也就是拖拽时对于键盘没有任何影响。
|
||||
|
||||
* UIScrollViewKeyboardDismissModeOnDrag:(dismisses the keyboard when a drag begins)当刚拖拽的时候就会回收键盘
|
||||
|
||||
* UIScrollViewKeyboardDismissModeInteractive:(the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss)当向下滑动的时候键盘会跟随手势一起下滑,当向上滑动的时候键盘也会跟随手势向上滑动而出现。
|
||||
Reference in New Issue
Block a user