按下时UITextField的动画大小

时间:2012-10-17 13:33:52

标签: objective-c uitextfield core-animation

我有一个文本字段,我想更改其内部触摸时的宽度和图像。图像没有任何问题地改变,但宽度保持不变。问题在某种程度上取决于触摸文本字段时触发的操作,因为当我创建一个简单的按钮时,动画可以正常工作。所以我的问题是如何在触摸文本字段时使动画工作。

动画在这里不起作用:

- (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){}
     ];

}

2 个答案:

答案 0 :(得分:0)

您是否在任何其他方法(如

)中触摸self.textFieldSearchStore的框架
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textField:shouldChangeCharactersInRange:replacementString:

或收听以下通知的方法:

UIKeyboardWillShowNotification
UIKeyboardDidShowNotification

或任何这些方法

– canBecomeFirstResponder
– becomeFirstResponder
– touchesBegan:withEvent:

如果是这样,我会在这些方法上设置一个断点,看看它们是否在上面的方法之后被调用。如果它有用,请告诉我。

答案 1 :(得分:0)

问题解决了。问题是我使用的是表视图控制器。更改为常规View Controller,现在它正在运行!