2013-04-11 111 views
0

我有一个按钮acton与出口btnAdd,当它按下它添加文本字段,我想要移动按钮行动也textfields下面和同样想要恢复时按钮BtnRemove按下,如何将按钮动作沿y轴移动iphone

- (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; 

} 

回答

1

一旦你已经修改了frame变量,将其设置为按钮,在动画块:

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

很明显,你可以在动画的持续时间(0.2)更改为任何你想。要将其反转,请执行相同操作,设置CGRect的原点,并将其设置为上面动画块中的按钮。

+0

你的代码给我错误 – NullData 2013-04-11 09:01:37

+0

有助于知道错误是什么?如果是这样的话,修正一个小的错字。 '(BOOL完成)'后面还有一个^ – 2013-04-11 10:47:11

+0

@QualityCoder最终为您工作了吗?如果有,请接受答案。谢谢。 – 2013-05-12 09:29:37

0
[UIView animateWithDuration: delay: options: animations: completion:]; 

会是你的选择。你可以检查文档here