Вопрос

I am trying to set an animation on my iOS app. The idea is to make a custom UIButton spin very fast to change its picture nicely. Basically I have two UIButtons with the same shape but different icons on them. When I make the keyboard appear, I make the one on top spin and fade out while the other one spins and then stops.

When I make the keyboard disappear, I'd like to trigger the same animation but the other way around.

My problem is that my two buttons spin only once. I can't manage to make them spin any other way.

Here is my code:

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

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

        [UIView setAnimationRepeatCount:3];
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
        self.main.transform = transform;
    } 
    completion:^(BOOL finished){

    }];

    [UIView animateWithDuration:0.3 animations:^{
        [UIView setAnimationDelay:0.0];
        self.main.alpha = 0.0;
    }];

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

        [UIView setAnimationRepeatCount:3];
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
        self.smiley.transform = transform;

    } completion:^(BOOL finished){

    }];

    [self animateTextField:myTextField up:YES];
}

- (void) textFieldDidEndEditing:(UITextField *)myTextField{

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionRepeat |    UIViewAnimationOptionCurveLinear animations:^{
        CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
        self.smiley.transform = transform;
    } completion:NULL];

    [UIView animateWithDuration:0.3 animations:^{
        self.main.alpha = 1.0;
    }];

    [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{

        [UIView setAnimationRepeatCount:3];
        CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
        self.main.transform = transform;
    } completion:^(BOOL finished){

    }];

    [self animateTextField:myTextField up:NO];
}

Does anyone have any idea how to fix this?

Many thanks for your help!

Это было полезно?

Решение

Would you mind trying with this:

CGAffineTransform transform = CGAffineTransformRotate(self.smiley.transform, M_PI);
self.smiley.transform = transform;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top