滚动时CollectionView滞后

时间:2017-12-25 06:00:35

标签: ios objective-c xcode uicollectionview uicollectionviewcell

先生,我是初学者。我无法理解这一点。我在滚动collectionView时面临滞后。我删除了Cell-shadow然后滞后了。但我想添加阴影。我的cellforItem代码是:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellIdentifier = @"cellCollection";
        [self.MainCollectionView registerClass:[CVC_ImageWithLabel class] forCellWithReuseIdentifier:cellIdentifier];
        CVC_ImageWithLabel *customCell = (CVC_ImageWithLabel *)[self.MainCollectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

        //cell text
        customCell.NameLabel.text = [data_Array objectAtIndex:indexPath.row];
        //cell image
        customCell.CellImage.image=[UIImage imageNamed:[image_Array objectAtIndex:indexPath.row]];
        customCell.CellImage.contentMode = UIViewContentModeScaleAspectFit;

        return customCell;
    }
先生,你能帮助我吗? 我试图添加下面的代码,但没有这样做。

customCell.layer.shouldRasterize = YES;
customCell.layer.rasterizationScale = [UIScreen mainScreen].scale;

2 个答案:

答案 0 :(得分:1)

您应该再设置一个图层属性 - shadowPath:

self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;
self.layer.shadowOffset = CGSizeMake(0, 1);
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect: self.bounds cornerRadius: self.layer.shadowRadius].CGPath;

此路径定义用于构造图层阴影的轮廓,而不是使用图层的合成Alpha通道。使用此属性显式指定路径通常可以提高渲染性能

答案 1 :(得分:0)

添加阴影作为图像,它的性能更好。您可以使用图像切片来帮助缩放图像。