UIScrollview 键盘遮挡问题
2015-01-22 18:15
369 查看
#pragma mark - UIKeyboard Obscure Problem - (void)handleKeyboardStuff { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapScrollView:)]; [_scrollView addGestureRecognizer:tap]; } - (void)keyboardWillShow:(NSNotification *)notification { [self adjustInsetForKeyboardShow:YES notification:notification]; } - (void)keyboardWillHide:(NSNotification *)notification { [self adjustInsetForKeyboardShow:NO notification:notification]; } - (void) tapScrollView:(id)sender { [_scrollView endEditing:YES]; } - (void)adjustInsetForKeyboardShow:(BOOL)show notification:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; CGRect keyboardFrame = ((NSValue *)userInfo[UIKeyboardFrameBeginUserInfoKey]).CGRectValue; CGFloat adjustmentHeight = (CGRectGetHeight(keyboardFrame) + 20.0) * (show ? 1 : -1); UIEdgeInsets scrollInsets = _scrollView.contentInset; scrollInsets.bottom += adjustmentHeight; _scrollView.contentInset = scrollInsets; UIEdgeInsets indicatorInsets = _scrollView.scrollIndicatorInsets; indicatorInsets.bottom += adjustmentHeight; _scrollView.scrollIndicatorInsets = indicatorInsets; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }
添加以上代码,最后在viewDidLoad方法里添加:
[self handleKeyboardStuff];
相关文章推荐
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法
- [操作系统]处理UIScrollView中的编辑框被弹出键盘遮挡的问题
- UIScrollView中的UITextField键盘遮挡问题的最简单解决办法 2012-10-31 15:10 1743人阅读 评论(0) 收藏 举报 两步: 1重载textFieldDidBe
- UItableView中含输入框(TextField)被键盘遮挡问题
- textView键盘遮挡问题
- tableviewcell 自动调整textfiled的键盘遮挡问题 UITableViewController中的tableview做可以自适应键盘高度来改变tableview的额外高度。
- Android WebView中软键盘会遮挡输入框相关问题
- ios tableView多个cell处理键盘遮挡内容视图的问题
- UIScrollView的使用2个妙招:键盘遮挡,View 支持滚动
- iOS 处理键盘遮挡TextField、TextView问题
- Android RecyclerView内容被键盘遮挡问题
- iOS开发 键盘遮挡输入框(TextView、TextField)问题
- Android WebView 软键盘遮挡输入框问题的解决方法
- textView键盘被遮挡问题
- Android WebView中软键盘会遮挡输入框相关问题
- ios解决webview键盘遮挡问题
- 《React-Native系列》42、键盘遮挡问题官方处理方法KeyboardAvoidingView
- Android WebView中软键盘会遮挡输入框相关问题