0

美好的一天..我有这段代码..这两个用于 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];
}

提前致谢!

4

1 回答 1

1

嗯……

您想一键启动/停止吗?

BOOL isAnimating = NO;

- (void)startStopAnimating 
{
    if (!isAnimating) {
       isAnimating = YES
       // start animation
    } else {
       isAnimating = NO;
       // stop animation
    }
}
于 2012-09-10T14:31:23.190 回答