简体   繁体   English

滚动UITableView时拉起键盘并与tableView一起滚动

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

To add panning behaviour to the keyboard, I am using DAKeyboardControl . 要向键盘添加平移行为,我使用的是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 . 如果用户尝试在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. 具体而言,我正在寻找类似Facebook的消息应用程序,在这里,如果你向上滚动显示的键盘,具有平移,并台滚动行为。

EDIT : It seems I am not clear about what I want. 编辑 :似乎我不清楚我想要什么。 I wish to move the keyboard along with the scrollview ( UITableView ). 我希望将键盘与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]; 通过将scrollview的keyboardDismissMode设置为UIScrollViewKeyboardDismissModeInteractive然后在scrollViewDidScroll:调用[textField becomeFirstResponder];可以实现此效果[textField becomeFirstResponder]; . Because you are in the middle of scroll, the keyboard will respect the keyboardDismissMode property and interactively appear. 因为您处于滚动的中间,键盘将尊重keyboardDismissMode属性并以交互方式显示。 Drop the DAKeyboardControl ; 放下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). 您需要一个元素,如UITextView ,然后检测滚动(例如,使用任何UIScrollView委托方法)。 Once scrolled, call becomeFirstResponder on the text view. 滚动后,在文本视图上调用becomeFirstResponder

add this in .h file… 在.h文件中添加...

@property (nonatomic, assign) CGFloat lastContentOffset

And add this in your .m file... 并在.m文件中添加...

- (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... 希望这会成功,没有测试过......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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