2012-10-17 14 views
0

我有一個文本字段,我想要改變它的寬度和圖像。圖像變化沒有任何問題,但寬度保持不變。這個問題在某種程度上取決於觸摸文本字段時觸發的動作,因爲當我創建一個簡單的按鈕時,動畫就起作用。所以我的問題是如何在觸摸文本字段時使動畫工作。按動UITextField時的動畫大小

動畫並不在這裏工作:

- (void)textFieldDidBeginEditing:(UITextField *)textField{ 

     [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut 
         animations:^{ 

         self.textFieldSearchStore.background = [UIImage imageNamed:@"text-field-small.png"]; 
         self.textFieldSearchStore.frame = CGRectMake(textFieldSearchStore.frame.origin.x, textFieldSearchStore.frame.origin.y, 248.0f, textFieldSearchStore.frame.size.height); 

        } 
        completion:^(BOOL finished){} 
    ]; 

} 

的動漫作品在這裏:

- (IBAction)test:(id)sender { 

    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut 
        animations:^{ 

         self.textFieldSearchStore.background = [UIImage imageNamed:@"text-field-small.png"]; 
         self.textFieldSearchStore.frame = CGRectMake(textFieldSearchStore.frame.origin.x, textFieldSearchStore.frame.origin.y, 248.0f, textFieldSearchStore.frame.size.height); 

        } 
        completion:^(BOOL finished){} 
    ]; 

} 
+0

下面的答案是否有幫助? – clearwater82

+0

恐怕不是。動畫無處不在,但在textFieldDidBeginEditing。 –

回答

0

問題解決。問題是我正在使用Table View Controller。更改爲常規視圖控制器,現在它正在工作!

0

你觸摸self.textFieldSearchStore的框架的任何其他方法一樣

– textFieldShouldBeginEditing: 
– textFieldDidBeginEditing: 
– textField:shouldChangeCharactersInRange:replacementString: 

或聽取以下通知的方法:

UIKeyboardWillShowNotification 
UIKeyboardDidShowNotification 

或任何這些方法

– canBecomeFirstResponder 
– becomeFirstResponder 
– touchesBegan:withEvent: 

如果是的話我會設置這些方法的斷點,看看他們是否有上述方法之後被調用。讓我知道它是否有用。

+0

是的,我正在使用textFieldDidBeginEditing方法,正如我在代碼片段中所示。但那是我用來觸摸框架的唯一方法。 –