增加点击事件
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenKey)];
[_myTableView addGestureRecognizer:tap];触发方法
- (void)hiddenKey {
[self.view endEditing:YES];
}防止键盘被覆盖
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];偏移
#pragma mark - keybord(监测键盘响应方法)
- (void)keyboardWillShow:(NSNotification *)notification {
[UIView animateWithDuration:0.25 animations:^{
[_myTableView setContentOffset:CGPointMake(0, 300)];
} completion:nil];
}
- (void)keyboardWillHide:(NSNotification *)notification {
[UIView animateWithDuration:0.25 animations:^{
[_myTableView setContentOffset:CGPointMake(0, 0)];
} completion:nil];
}
本文详细介绍了如何在iOS应用中通过增加点击事件和优化键盘交互,实现更好的用户体验。包括使用UIGestureRecognizer处理点击事件,自定义键盘显示与隐藏的行为,以及在键盘出现时调整UI布局以避免遮挡内容。
7125

被折叠的 条评论
为什么被折叠?



