사용자 지정 레이아웃을 사용하여 UICollectionView를 설정하려고합니다. 각 CollectionViewCell의 내용은 이미지입니다. 전체적으로 수천 개의 이미지가 있고 특정 시간에 140-150 개의 이미지가 표시됩니다. 액션 이벤트에서 잠재적으로 모든 셀이 위치와 크기로 재구성됩니다. 목표는 현재 performBatchUpdates 메소드를 사용하여 움직이는 모든 이벤트에 애니메이션을 적용하는 것입니다. 이로 인해 모든 것이 애니메이션으로 표시되기 전에 엄청난 지연 시간이 발생합니다.performBatchUpdates의 UICollectionView 성능 문제
이번에는 내부적으로 layoutAttributesForItemAtIndexPath 메서드가 모든 단일 셀 (총 수천 개)에 대해 호출된다는 것을 알았습니다. 또한 cellForItemAtIndexPath 메서드는 실제로 화면에 표시 할 수있는 것보다 많은 셀에 대해 호출됩니다.
애니메이션의 성능을 향상시킬 수있는 방법이 있습니까?
기본적으로 UICollectionViewFlowLayout은 앱에서 실현시키고 싶은 디자인을 제공 할 수 없습니다. 여기에 우리의 코드 중 일부의 다음 RECT 내 allthe 요소 layoutAttributes을 설정하는 모든 요소를
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RPDataModel *dm = [RPDataModel sharedInstance]; //Singleton holding some global information
NSArray *plistArray = dm.plistArray; //Array containing the contents of the cells
NSDictionary *dic = plistArray[[indexPath item]];
RPCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
cell.label.text = [NSString stringWithFormat:@"%@",dic[@"name"]];
cell.layer.borderColor = nil;
cell.layer.borderWidth = 0.0f;
[cell loadAndSetImageInBackgroundWithLocalFilePath:dic[@"path"]]; //custom method realizing asynchronous loading of the image inside of each cell
return cell;
}
layoutAttributesForElementsInRect 반복은. 세포의 수를 정의되는 경우 결과가 거의없이 동일하다 레이아웃에
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray* attributes = [NSMutableArray array];
RPDataModel *dm = [RPDataModel sharedInstance];
for (int i = 0; i < dm.cellCount; i++) {
CGRect cellRect = [self.rp getCell:i]; //self.rp = custom object offering methods to get information about cells; the getCell method returns the rect of a single cell
if (CGRectIntersectsRect(rect, cellRect)) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:[dm.relevanceArray[i][@"product"] intValue] inSection:0];
UICollectionViewLayoutAttributes *attribute = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
attribute.size = cellRect.size;
attribute.center = CGPointMake(cellRect.origin.x + attribute.size.width/2, cellRect.origin.y + attribute.size.height/2);
[attributes addObject:attribute];
} else if (cellRect.origin.x > rect.origin.x + rect.size.width && cellRect.origin.y > rect.origin.y + rect.size.height) {
break;
}
}
return attributes;
}
가 변경 : 첫 번째 셀에 대한 문 휴식은 RECT의 오른쪽 하단 모서리에 의해 정의 된 경계를지나 인 layoutAttributesForElementsInRect가 제한되어 있거나 제한되어 있습니다. 제한되지 않은 경우 시스템이 모든 셀의 레이아웃 속성을 가져 오거나 제한된 경우 모든 누락 된 셀에 대해 layoutAttributesForElementAtIndexPath 메소드를 호출합니다. 전반적으로 모든 단일 셀의 속성이 어떻게 든 사용되고 있습니다. 코드를 보지 않고
-(UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
RPDataModel *dm = [RPDataModel sharedInstance];
UICollectionViewLayoutAttributes *attribute = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
CGRect cellRect = [self.rp getCell:[dm.indexDictionary[@(indexPath.item)] intValue]];
attribute.size = cellRect.size;
attribute.center = CGPointMake(cellRect.origin.x + attribute.size.width/2, cellRect.origin.y + attribute.size.height/2);
return attribute;
}
UICollectionViewLayout에서 코드를 게시하십시오. –