如何在UITableview的CustomCell中单击UITextField时向上移动查看?

jam*_*mil 1 iphone keyboard xcode uitextfield uiviewanimation

我在UITableview的自定义单元格中有TextField.我的Tableview是MainView的下半部分所以当我在CustomCell键盘上单击TextField时出现哪个HIde我的textfield.My下面的图像显示我的问题

在此输入图像描述

在这里我有一个代码,当我在MainView.please中有UITextField时,编辑下面的代码,因为我想要整个视图动画,当我点击UITextfield.

-(void)textFieldDidBeginEditing:(UITextField *)textField {

if (textField.tag > 0) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0,
                                 self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}   

   }
 -(void)textresign{

[[self.view viewWithTag:1]resignFirstResponder];
   }
-(void)textFieldDidEndEditing:(UITextField *)textField {         
if (textField.tag > 0) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0,
                                  self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}   

  }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何修复它为我的自定义单元格UITextField.Any帮助将被适用.

Kam*_*had 5

这里是代码,只需要稍微改变代码

-(void)textFieldDidBeginEditing:(UITextField *)textField
{

    if (textField.tag > 0)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationBeginsFromCurrentState:YES];
        self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-165.0,
                                     self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];
    }
}
Run Code Online (Sandbox Code Playgroud)

使用下面的方法重新定位键盘上的视图而不是 textFieldDidEndEditing.

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    if (textField.tag > 0)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationBeginsFromCurrentState:YES];
        self.view .frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+165.0,
                                      self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];

    }
    [textField resignFirstResponder];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

使用以下方法,必须将委托设置为文本字段.

我希望你能得到解决方案.