我有一个问题。我在CollectionView Cell中有一个按钮,当它第一次被触摸时会移动。这是“移动”代码:
[UIView animateWithDuration:0.5 animations:^{
_button.frame = CGRectMake(80,112,30,20);
}];
但是当我向下滚动并再次向上滚动时,在旧地方再次创建了相同的按钮,我该如何解决?移动的按钮仍在那里 - >单元格中的按钮是两次。 以下是按钮的创建方式:
-(UIButton *)button{
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(111,112,30,20);
[_button setImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
_button.backgroundColor = [UIColor clearColor];
[_button addTarget:self
action:@selector(decMethod)
forControlEvents:UIControlEventTouchUpInside];
return _button;
}
这里是CollectionView Cell:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CHTCollectionViewWaterfallCell *cell =
(CHTCollectionViewWaterfallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
forIndexPath:indexPath];
[cell addSubview:cell.buttonInc];
return cell;
}
谢谢你!
答案 0 :(得分:0)
UICollection将在性能需要时杀死不在屏幕外的单元格。在您的情况下,您可以创建一个NSMutableArray来记录所有移动历史记录的单元格。如果一个单元格已经移动,则将YES设置为相应的数组索引。在为按钮设置动画之前,只需检查数组以查找它是否已被移动。