我有问题 我在表格视图中有15个文本字段。当我输入文本到最后一个文本字段时,它是由键盘覆盖。任何人请给我一个解决方案。
我的文本字段位于IPAD分割视图的详细视图中,
提前感谢您的解决方案
答案 0 :(得分:0)
您可以添加以下编码行:
//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)
{
NSLog(@"MOVE-UP");
// 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
{
NSLog(@"MOVE-DOWN");
// 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)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];
}
}
在viewDidAppear中:
-(void)viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
你必须定义这个#define kOFFSET_FOR_KEYBOARD 100.0 //你想要的
答案 1 :(得分:0)
//文本字段编辑开始时调用
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self animateTextField: indexPath up: YES];
}
//编辑结束后的文字字段
(void)textFieldDidEndEditing:(UITextField *)textField {
[self animateTextField: indexPath up: NO];
}
// animateTextField的代码。移动距离将根据需要改变
(void)animateTextField:(NSIndexPath *)indexPath up:(BOOL)up {
const int movementDistance = indexPath.section == 0?20:180;
const float movementDuration = 0.3f;
int movement =(up?-movementDistance:movementDistance);
的NSLog(@ “运动:%d”,移动);
[UIView beginAnimations:@“aimation”context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:movementDuration];
self.view.frame = CGRectOffset(self.view.frame,0,move);
[UIView commitAnimations];
}