如何设置水平/ LeftToRight动画?

时间:2013-11-25 15:50:02

标签: ios animation

我垂直动画没有问题,但我需要对水平动画的值做些什么?即使是苹果指南中内置的动画,也没有为水平动画提供任何参考。只是垂直覆盖。使用Objective-C在XCode 5中编写iOS代码。谢谢!

        - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
        if (textField == self.passwordTextField) {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDelegate:self];
            [UIView setAnimationDuration:0.4];
            [UIView setAnimationBeginsFromCurrentState:YES];
            self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 40), self.view.frame.size.width, self.view.frame.size.height);
            [UIView commitAnimations];
    - (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == self.passwordTextField) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.4];
        [UIView setAnimationBeginsFromCurrentState:YES];
        self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 40), self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];

1 个答案:

答案 0 :(得分:1)

self.view.frame = CGRectMake((self.view.frame.origin.x - 20),(self.view.frame.origin.y - 40),self.view.frame.size.width,self .view.frame.size.height);

然后,您将移动X 20像素到