0

我有一个带有出口 btnAdd 的按钮操作,当它按下它时添加文本字段,我想将按钮操作也移动到文本字段下方,并且同样希望在按下按钮 BtnRemove 时恢复,

 - (IBAction)btnAddTxtField:(id)sender {

    textField = [[UITextField alloc] initWithFrame:CGRectMake(76, ([txtFieldArray count] * 30), 191, 25)];
    [textField setBorderStyle:UITextBorderStyleLine];
    textField.font = [UIFont systemFontOfSize:20];
    textField.placeholder = @"Enter text";
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    textField.delegate = self;
    [myScrollview addSubview:textField];
    [txtFieldArray addObject:textField];


    CGRect frame = bottomView.frame;
    frame.origin.y += textField.frame.size.height + 5;

    btnAdd = [[UIButton alloc] initWithFrame:CGRectMake(210, ([txtFieldArray count] *30), 20, 20)];
   frame.origin.y += btnAdd.frame.size.height +5;
    bottomView.frame = frame;
    textField.hidden = NO;

}
4

2 回答 2

1

修改frame变量后,将其设置为动画块中的按钮:

 [UIView animateWithDuration:0.2 animations:^{
     [btnAdd setFrame:frame];
 } 
 completion:^(BOOL finished){
      //Do something on completion if you want
 }];

显然,您可以将动画持续时间 (0.2) 更改为您想要的任何内容。要反转它,请执行相同操作,设置 CGRect 的frameorigin.y,并将其设置为上面动画块中的按钮。

于 2013-04-11T08:19:52.660 回答
0
[UIView animateWithDuration: delay: options: animations: completion:];

会是你的选择。您可以在此处查看文档。

于 2013-04-11T07:54:11.493 回答