0
질문이 있습니다. 나는 CollectionView Cell 안에 버튼을 가지고 있는데, 처음 터치했을 때 움직인다. 여기에 "이동"코드 :스크롤하면서 새로운 버튼을 만들려면 CollectionView를 중지하십시오.
[UIView animateWithDuration:0.5 animations:^{
_button.frame = CGRectMake(80,112,30,20);
}];
하지만 아래로 스크롤 다시 스크롤 할 때, 옛 자리에 다시 만든 같은 버튼은 어떻게 고칠 수 있나요? 이동 한 버튼은 여전히 있습니다 -> 버튼이 셀에 두 번 있습니다. 여기에 CollectionView 셀
-(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;
}
과 :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CHTCollectionViewWaterfallCell *cell =
(CHTCollectionViewWaterfallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
forIndexPath:indexPath];
[cell addSubview:cell.buttonInc];
return cell;
}
당신을 감사 여기 버튼 만드는 방법입니다!
작동하지 않습니다. CollectionView는 첫 번째 위치에 새 단추를 무작위로 추가합니다. – seniorbenelli
때문에 collectionView는 성능 문제에 대해 자동으로 셀을 다시 사용합니다. 처음 버튼을 원하지 않으면 버튼이있는 경우 셀의 contentView 하위 뷰를 확인한 다음 제거하십시오. – Jing
괜찮습니다. 고맙습니다 – seniorbenelli