3D touch 导致UITableView或UICollectionView卡顿问题

经过排查,发现导致卡顿是如下原因,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;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容