简体   繁体   English

使用NSTimer的序列动画

[英]Sequence Animation using NSTimer

good day.. I have this code.. and this two is for actionAnimating Button and stopAnimating Button..I just want to know if how to make those two button integrate in ONE button.. for example.. I click the button then it animates.. when I click again that actionAnimating Button, i want to cancel/stop the animation at the same time i want to play/animate again.. in short i want to cancel the animation when i click again the actionAnimating button.. 美好的一天..我有这段代码..这两个是用于actionAnimating Button和stopAnimating Button ..例如,我只想知道如何使这两个按钮集成到一个按钮中。动画..当我再次单击该actionAnimating按钮时,我想同时取消/停止动画,我想再次播放/动画..总之,当我再次单击actionAnimating按钮时,我想取消动画。

-(void)flowerAnimationSequence//START ANIMATION
{
    MotherView.alpha = 0;
    flower.alpha = 0;
    [animationContainer1 removeFromSuperview];
    actselected = YES;

    NSLog(@"start");
    if (((sequenceAnimateCounter == 0) || (sequenceAnimateCounter==1)) && (actselected = YES))
    {
        aImageViewSlideShow = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
        aImageViewSlideShow.tag = 171;
        [self.view addSubview:aImageViewSlideShow];

    }

    if (sequenceAnimateCounter < 183) 
    {
        timer = [NSTimer scheduledTimerWithTimeInterval:0.035 target:self selector:@selector(flowerAnimationSequence) userInfo:nil repeats:NO];
    }

    else if (sequenceAnimateCounter ==183) 
    {
        aImageView = (UIImageView *)[self.view viewWithTag:171];
        NSLog(@"done");
        actselected = NO;
        sequenceAnimateCounter = 0;
        [aImageView removeFromSuperview];
        aImageView = nil;
        [self DefaultPosition];
    }


    aImageView = (UIImageView *)[self.view viewWithTag:171];

    NSString *aStrNumber =  [NSString stringWithFormat:@"%i",sequenceAnimateCounter];
    NSString *aBundlePath = [[NSBundle mainBundle]bundlePath];
    NSString *aImagePath = [NSString stringWithFormat:@"%@/sapatos_%@.png",aBundlePath,aStrNumber];

    [aImageView setImage:[UIImage imageWithContentsOfFile:aImagePath]];
    [self.view bringSubviewToFront: aImageView];
    sequenceAnimateCounter = sequenceAnimateCounter+1;

    if (sequenceAnimateCounter == 1)
    {
        [aImageView removeFromSuperview];
    }
}


-(void)stopanim//STOP BUTTON
{
        [timer invalidate];
        sequenceAnimateCounter =0;
        NSLog(@"stop");
        [aImageView removeFromSuperview];
}

thanks in advance! 提前致谢!

Hm... 嗯...

you want to start/stop in one button? 您要一键启动/停止吗?

BOOL isAnimating = NO;

- (void)startStopAnimating 
{
    if (!isAnimating) {
       isAnimating = YES
       // start animation
    } else {
       isAnimating = NO;
       // stop animation
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM