经过排查,发现导致卡顿是如下原因,cell一直做registerForPreviewingWithDelegate行为,导致滑动越来越卡
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"xxxx" forIndexPath:indexPath];
if ([[WW3DTouchHelper sharedHelper] support3DTouchWithViewController:self]) {
[self registerForPreviewingWithDelegate:self sourceView:cell];
cell.isAllreadySetupPreviewingDelegate = YES;
}
return cell;
}
修改方式如下,防止cell多次注册
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"xxxx" forIndexPath:indexPath];
if (!cell.isAllreadySetupPreviewingDelegate && [[WW3DTouchHelper sharedHelper] support3DTouchWithViewController:self]) {
[self registerForPreviewingWithDelegate:self sourceView:cell];
cell.isAllreadySetupPreviewingDelegate = YES;
}
return cell;
}