简体   繁体   中英

Pull up keyboard while scrolling UITableView and scroll along with the tableView

To add panning behaviour to the keyboard, I am using DAKeyboardControl . It works just fine (after modifications) for panning behaviour to close the keyboard.

How do I make the keyboard appear if the user tries to scroll downwards (finger pan in up direction) at the end of the UITableView . To be more specific, I am looking for behaviour similar to the Facebook Messages app, where, if you scroll up the keyboard appears, with panning, and scrolls with the table.

EDIT : It seems I am not clear about what I want. I wish to move the keyboard along with the scrollview ( UITableView ). In the following image, I am panning the keyboard along with the table. The table is already scrolled to it's bottom, and if I try to scroll down any further the keyboard begins to appear. My finger, meanwhile, is in the middle of the table.

在此输入图像描述

This effect can be achieved by setting the scrollview's keyboardDismissMode to UIScrollViewKeyboardDismissModeInteractive and then in scrollViewDidScroll: calling [textField becomeFirstResponder]; . Because you are in the middle of scroll, the keyboard will respect the keyboardDismissMode property and interactively appear. Drop the DAKeyboardControl ; it's outdated.

You need an element such as UITextView and then, detect the scroll (for example, using any of the UIScrollView delegate methods). Once scrolled, call becomeFirstResponder on the text view.

add this in .h file…

@property (nonatomic, assign) CGFloat lastContentOffset

And add this in your .m file...

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
   if (self.lastContentOffset > scrollView.contentOffset.y)
   {
       [textField becomeFirstResponder];
   }
   else if (self.lastContentOffset < scrollView.contentOffset.y) 
   {
       [textField resignFirstResponder];
   }
   self.lastContentOffset = scrollView.contentOffset.y;

}

Hope this will do the trick, haven't tested it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM