[英]Textview Inside table footer view not scroll to visible area when keyboard appears
I have added one tableview
inside xib
. 我在
xib
添加了一个tableview
。 After that I have added headerview
and footerview
in that. 之后,我在其中添加了
headerview
和footerview
。 Inside footerview
there is one textview
. 在
footerview
有一个textview
。 Textview can't scroll
to visible area once keyboard
appears. keyboard
出现后,Textview无法scroll
到可见区域。
Let me know anyone facing the same issue. 让我知道遇到同样问题的任何人。
This behavior is not handled by default. 默认情况下不处理此行为。 You have to implement it yourself.
您必须自己实施。
The other solution is to use UITableViewController
instead of UITableView
, which implements this behavior by default. 另一种解决方案是使用
UITableViewController
而不是UITableView
,它默认情况下实现了此行为。 You could put the UITableViewController
in a UIContainerView
if you don't want it to take the whole frame. 如果不希望
UITableViewController
占用整个框架,则可以将其放在UIContainerView
。
See code here if you want to implement the behavior yourself How to make a UITextField move up when keyboard is present? 如果您想自己实现该行为,请参见此处的代码如何在有键盘的情况下使UITextField向上移动?
Hope it helps. 希望能帮助到你。
Here is some sample code:
这是一些示例代码:
#define kOFFSET_FOR_KEYBOARD 80.0
-(void)keyboardWillShow {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)keyboardWillHide {
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:mailTf])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
CGRect rect = self.view.frame;
if (movedUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.