Iphone iOS静态单元格、自动滚动和附加工具栏键盘
我目前正在编写一个主要由表单组成的应用程序。 为了完成这项工作,我将使用静态单元格和UITableViewController,它可以包含UITextField和UITextView。 如果您使用的是该语言的默认配置,那么一切都相当好。 但对于UITextView,缺点是不能隐藏键盘,因为点击返回键将跳转到下一行。 因此,我放了一个工具栏来启用键盘关闭功能(键盘上有NSNotification)。 但是当它滚动到包含textfield的单元格时,该字段被工具栏隐藏,滚动不会增加工具栏的高度。 截图: 在单击字段之前 单击字段后Iphone iOS静态单元格、自动滚动和附加工具栏键盘,iphone,ios,uitableview,keyboard,scroll,Iphone,Ios,Uitableview,Keyboard,Scroll,我目前正在编写一个主要由表单组成的应用程序。 为了完成这项工作,我将使用静态单元格和UITableViewController,它可以包含UITextField和UITextView。 如果您使用的是该语言的默认配置,那么一切都相当好。 但对于UITextView,缺点是不能隐藏键盘,因为点击返回键将跳转到下一行。 因此,我放了一个工具栏来启用键盘关闭功能(键盘上有NSNotification)。 但是当它滚动到包含textfield的单元格时,该字段被工具栏隐藏,滚动不会增加工具栏的高度。 截
任何人都有一个神奇的代码片段来做这个把戏吗?a.,谢谢你的提示,我修改了代码,现在它可以工作了。以下是工作代码:
/**
* Cette méthode affiche la toolbar pour terminer l'adition quand le clavier est affiché
*
* @param NSNotification notification Notification de l'émetteur
*/
- (void)keyboardWillShow:(NSNotification *)notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect frame = self.toolbarAction.frame;
frame.origin.y = self.parentViewController.view.frame.size.height - 260.0;
self.toolbarAction.frame = frame;
// Cette portion de code permet de remonter le scroll (à cause de la toolbar)
if (![[AppKit sharedInstance] isIPad]) {
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y = tableFrame.origin.y - 50;
self.tableView.frame = tableFrame;
}
[UIView commitAnimations];
// Action pour les keyboards
self.toolbarDoneButton.tag = 1;
}
/**
* Cette méthode cache la toolbar lorsque le clavier n'est plus affiché
*
* @param NSNotification notification Notification de l'émetteur
*/
- (void)keyboardWillHide:(NSNotification *)notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect frame = self.toolbarAction.frame;
frame.origin.y = self.parentViewController.view.frame.size.height;
self.toolbarAction.frame = frame;
// Cette portion de code permet de rebaisser le scroll (à cause de la toolbar)
if (![[AppKit sharedInstance] isIPad]) {
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y = tableFrame.origin.y + 50;
self.tableView.frame = tableFrame;
}
[UIView commitAnimations];
}
解决此问题的有趣部分是:
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y = tableFrame.origin.y - 50;
self.tableView.frame = tableFrame;
在调用UITextView键盘并使textview对用户可见时,您需要降低tableview框架高度。您需要在TextViewDiBeginAgiting:方法中进行此操作。请共享您的代码好吗?所以其他人可能会觉得更容易。