1

我在 UITableview 的自定义单元格中有 TextField。我的 Tableview 是 MainView 的下部,所以当我单击 CustomCell 键盘中的 TextField 时,会出现哪个隐藏我的文本字段。我的下图显示了我的问题

在此处输入图像描述

在这里,当我在 MainView 中有 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];
}   

  }

但我不知道如何为我的自定义单元 UITextField 修复它。任何帮助都会被应用。

4

1 回答 1

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];
    }
}

使用以下方法重新定位键盘上的视图,而不是 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;
}

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

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

于 2012-11-12T15:07:57.250 回答