Hide Keyboard When Scroll Uitableview

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



Leave a reply



Submit