[英]how to move button action down along y axis iphone
i have a button acton with outlet btnAdd, when it pressed it add text field, i want to move button action also below textfields and same want to recover back when button BtnRemove pressed, 我有一个带有按钮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;
}
Once you have modified the frame
variable, set it to the button in an animation block: 修改
frame
变量后,将其设置为动画块中的按钮:
[UIView animateWithDuration:0.2 animations:^{
[btnAdd setFrame:frame];
}
completion:^(BOOL finished){
//Do something on completion if you want
}];
Obviously you can change the animation duration (0.2) to anything that you would like. 显然,您可以将动画持续时间(0.2)更改为所需的任何值。 To reverse it, do the same, set the origin.y of the
frame
CGRect, and set it to the button in the animation block above. 要反转它,请执行相同的操作,设置
frame
CGRect的origin.y,并将其设置为上方动画块中的按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.