CollectionView 中的 iOS UIButton,以仅在该单元格上触发自定义动画



我有一个CollectiveView,里面有各种各样的元素。我已经设法添加一个按钮并附加了一个操作。按下按钮时,我希望该调用执行某项活动,例如更改背景颜色......

目前,此活动正在应用于所有细胞。任何建议表示赞赏。

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.label.text = [NSString stringWithFormat:@"%ld",(long)indexPath.item];
cell.trackLbl.text = [NSString stringWithFormat:@"Track %ld", (long)indexPath.row + 1];
cell.trackTitle.image = [UIImage imageNamed:[[self.util trackTitleImages] objectAtIndex:indexPath.row]];
[cell.record addTarget:self
                action:@selector(recording:)
      forControlEvents:UIControlEventTouchUpInside];

if (isRecording) {
    [cell.spinnerWidget beginCompletion:[UIColor redColor]];
}
else {
    [cell.spinnerWidget beginCompletion:[UIColor colorWithRed:0.45f green:0.77f blue:0.87f alpha:1.0f]];
}
[self.view setNeedsDisplay];
return cell;
}

如您所见,目前我将"录制"目标分配给我的单元格uibutton。由此,我还可以获得单元格的索引。我的解决方法是有一个布尔值(isRecording)并重新加载数据。但显然这适用于所有单元格。

如果按钮在单元格中,请使用超级视图。例如在背景颜色的情况下

@IBAction func buttonPressed(sender: AnyObject) {
    yourButton.superview.backgroundColor = UIColor(your values here)
}

最新更新