我已经为“滑块解锁”元素创建了一个 UISlider。我写的动画只指向一个滑块时效果很好。但我需要使用 for 循环来动态创建滑块。当我创建滑块为滑块添加标签并将动画功能添加到 for 循环中的滑块时,动画不起作用,如下所示:
for (int i = 0; i < rowCount; i++){
    ...
    UISlider *slider=[[UISlider alloc] initWithFrame:CGRectMake(5+ xInc, 25+yInc, 322, 40)];
    //give a id tag to the slider
    [slider setTag:i*10];
    //set a action to the slider
    [slider addTarget:self action:@selector(UnlocklinkSlider:) forControlEvents:UIControlEventTouchUpInside];
    ...
动画功能是:
- (void)UnlocklinkSlider:(UISlider*)slider
 {
    for (int i = 0; i < rownumber; i++){
        UIImageView *frontimg = (UIImageView *)[self.view viewWithTag:i*10+1];
        ...
        if (slider.tag==i*10) {
            if(slider.value >= 0.5){
                // user did not slide far enough, so return back to 0 position
                [UIView beginAnimations: @"SlideCanceled" context: nil];
                [UIView setAnimationDelegate: self];
                [UIView setAnimationDuration: 0.35];
                // use CurveEaseOut to create "spring" effect
                [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
                ...
                [UIView commitAnimations];
                ...
            }
            else{
                ...
            }
        }
    }
 }
但是动画不能以这种方式工作。有人知道为什么吗?