我有一个带有插座btnAdd的按钮acton,当它按下它时添加文本字段,我想在文本字段下方移动按钮动作,同样想要按下按钮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;
}
答案 0 :(得分:1)
修改frame
变量后,将其设置为动画块中的按钮:
[UIView animateWithDuration:0.2 animations:^{
[btnAdd setFrame:frame];
}
completion:^(BOOL finished){
//Do something on completion if you want
}];
显然,您可以将动画持续时间(0.2)更改为您想要的任何内容。要反转它,请执行相同操作,设置frame
CGRect的origin.y,并将其设置为上面动画块中的按钮。
答案 1 :(得分:0)
[UIView animateWithDuration: delay: options: animations: completion:];
将是您的选择。您可以查看文档here。