views:

76

answers:

2

Hello . I have some UIImageViews and when the user is touching, an animation with a certain duration starts. A trigger counts ++ and with the next touch another animation starts to play. But if the user touches to fast or make a doubletouch the first animation does not finish until the last frame. I tried the "sleep()" command, but it does not work.

    #pragma mark HenneAnimation
    if([touch view] == ani_Henne){

        //trigger strats with zero
        switch (trigHenne) {
            case 0:
//firstanimation 1 sec
                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne02.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],
                                             [UIImage imageNamed:@"ani_Henne01.png"],nil];


                ani_Henne.animationDuration = 1;
                ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;

            case 1:
//second animation 1 sec                
                ani_Henne.animationImages = [NSArray arrayWithObjects:

                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],
                                             [UIImage imageNamed:@"ani_Henne04.png"],
                                             [UIImage imageNamed:@"ani_Henne05.png"],
                                             [UIImage imageNamed:@"ani_Henne03.png"],nil];              
                ani_Henne.animationDuration = 3;
                ani_Henne.animationRepeatCount = 1;
            [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;

                break;

            case 2:
                [self.view bringSubviewToFront:ani_Henne];

                ani_Henne.animationImages = [NSArray arrayWithObjects:
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne06.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne07.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],
                                             [UIImage imageNamed:@"ani_Henne09.png"],
                                             [UIImage imageNamed:@"ani_Henne08.png"],nil];

                ani_Henne.animationDuration = 2.75;
            ani_Henne.animationRepeatCount = 1;
                [ani_Henne startAnimating];
                [self.view addSubview:ani_Henne];

                trigHenne++;
                break;
            case 3:
                trigHenne=0;
// etc. animations
                break;
            default:
                break;  
        }       
    }
A: 

When you begin to animate set the userinteraction disabled, and when you are done, reenable it like:

yourImageView.userInteractionEnabled = NO;

yourImageView.userInteractionEnabled = YES;

you could also delay the enabling with

...
[self performSelector:@selector(enable) withObject:yourImageView afterDelay:1.0];
...


-(void)enable
{
yourImageView.userInteractionEnabled = YES
}
Gauloises
Thank You! I'll try it this evening.
FredIce
Thank You, it works like I want it!It's better and easier than the beginIgnoringInteractionEvents-solution, because only the choosen View is disabled for input!
FredIce
glad to be of help.
Gauloises
A: 

Using UIApplications beginIgnoringInteractionEvents and endIgnoringInteractionEvents might help you, when begin is called UI interaction events from user are ignored, here is a reference UIApplication ref

Daniel
Thank you very much for this hint!
FredIce
I've done it like this:case 0: [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; [UIView beginAnimations:nil context:nil]; { [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //geschmeidige Bewegeung [UIView setAnimationDuration:10.0f]; [UIView setAnimationDelegate: self]; ani_schwein_gross.transform = CGAffineTransformMakeTranslation (-200, 10); [UIView setAnimationDidStopSelector: @selector(doneSwappingViewsAnimation:finished:context:)]; } [UIView commitAnimations];etc.The animation finish - and any input is disabled.
FredIce
before ViewDIdLoad I inserted:- (void) doneSwappingViewsAnimation: (NSString*) idfinished: (BOOL) finished context: (id) context{ [[UIApplication sharedApplication] endIgnoringInteractionEvents];}
FredIce
is the doneSwapping method being called?
Daniel