2013-04-11 114 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