Hide keyboard when scroll UITableView
Not sure why you need to subclass UITableView for this.
In the view controller that contains the plain UITableView, try adding this:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[searchBar resignFirstResponder];
}
How to show/hide keyboard smoothly on drag in iOS Swift 3?
If you have a UIScrollView
(or a UITableView
/UICollectionView
since they inherit from UIScrollView
) you can simply set keyboardDismissMode
property to interactive
.
Objective-C :
self.scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
Swift
self.scrollView.keyboardDismissMode = .interactive
As usual, more in the docs.
Dismiss Keyboard On drag
Implement the scroll view delegate method (scrollViewWillBeginDragging
). In this method resignFirstResponder
your search bar. You can also look at this SO answer.
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
searchController.searchBar.resignFirstResponder()//self.searchBar?.endEditing(true)
}
How to dismiss keyboard in a tableView after typing in textview
You can use the UITableViewDelegate
which conforms to the UIScrollViewDelegate
to implement:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
dismissKeyboard()
}
func dismissKeyboard(){
self.view.endEditing(true)
}
//Add to viewDidLoad:
var tapGesture = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
tableView.addGestureRecognizer(tapGesture)
//Or since you wanted to dismiss when another cell is selected use:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
dismissKeyboard()
}
Hide keyboard when we scroll with TableView after we searched
You need to track the action that runs when the tableView is being scrolled. UITableView
is the subclass of UIScrollView
. So, you can use all the methods from UIScrollViewDelegate
for your table.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[textfield resignFirstResponder];
}
This will work.
How to hide keyboard on touch UITableView in iOS Obj-C
This is the simplest way to dismiss keyboard
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[tableView addGestureRecognizer:gestureRecognizer];
}
- (void)hideKeyboard
{
[self.view endEditing:YES];
}
How to hide keyboard with animation while scrolling tableview iphone
Hold a reference to your UITextField/UItextView
(btw, here is a nice component that mimic the behaviour you described).
As you pointed out, you can then implement this method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.textFieldRef resignFirstResponder];
}
EDIT
Question is a possible duplicate of iMessage Style Receding Keyboard in an iOS App and How to move iPhone keyboard down like in Messages.app?
Related Topics
How to Draw a Circle Path with Color Gradient Stroke
What Impact Does Simulated Metrics Have
How to Keep Uiswitch State When Changing Viewcontrollers
Expected Declaration Error for Making High Score
How to Make an iOS Asset Bundle
Uiview Touch Event in Controller
How to Change the Height of a Uinavigationbar in Storyboard Without Using a Uinavigationcontroller
Exc_Bad_Instruction (Code=Exc_I386_Invop, Subcode=0X0) on Dispatch_Semaphore_Dispose
Blocks on Swift (Animatewithduration:Animations:Completion:)
Create PDF with Multiple Pages
How to Edit Uialertaction Text Font Size and Color
How to Convert an Int to a Character in Swift
Swiftui Landmarks App Tutorial Screen Navigates Back When Toggle Favorite
How to Resize Table Cell Based on Textview
Creating Thumbnail from Local Video in Swift