【问题标题】:stop animation when button is pressed按下按钮时停止动画
【发布时间】:2014-12-26 07:59:32
【问题描述】:

我有下面的代码,它是一个 UIButton 的动画。但是当按下按钮时,我希望动画立即停止并做其他事情,而如果动画继续,它会做其他事情。我的问题是,即使我按下按钮,动画也会继续,它会执行第 1 步和第 2 步。

我在代码中遗漏了什么?

int frame1 = 600;
    int frame2 = 100;
    hit11 = [[UIButton alloc]initWithFrame:CGRectMake((arc4random() % (frame1 - frame2)+frame2),200,20,20)];
      [hit11 addTarget:self action:@selector(hit:) forControlEvents:UIControlEventTouchUpInside];
    [hit11 setBackgroundImage:[UIImage imageNamed:@"touchrightdown.png"] forState:UIControlStateNormal];
    [self.view addSubview:hit11];
    [UIView animateWithDuration:2.0 delay:0.1 options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
        hit11.transform = CGAffineTransformMakeScale(7,7);
        hit11.alpha=0.5;
    } completion:^(BOOL finished) {
        if (finished) {
            //DO STEP 2.
hit11.hidden=YES;

        }



        NSLog(@"got hit");


    }];

-(void) hit:(UIButton*)sender{
    NSLog(@"1/10");
    //DO STEP 1.
}

【问题讨论】:

    标签: ios objective-c iphone animation uibutton


    【解决方案1】:

    尝试添加这个:

    [sender.layer removeAllAnimations];
    

    在您的点击中:(UIButton*)sender 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多