【问题标题】:how to display Circular progress bar in UICollectionviewCell?如何在 UICollectionviewCell 中显示圆形进度条?
【发布时间】:2015-08-25 09:53:43
【问题描述】:

如何在 uicollectionview 中使用惰性显示圆形进度条 正在加载图片。

        ClothCell weakCell = (ClothCell )[collectionView dequeueReusableCellWithReuseIdentifier:@"ClothesCell" forIndexPath:indexPath];
        weakCell.tag=indexPath.item;
        weakCell.contentView.opaque = NO;
        weakCell.contentView.clipsToBounds = YES;
        weakCell.opaque = YES;
        weakCell.clipsToBounds = YES;
        weakCell.contentView.backgroundColor = [UIColor clearColor];
        Clothes *clothes = [self.arrayClothes objectAtIndex:indexPath.item];
        [weakCell.imageViewCloth setImage:nil];
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
     //   dispatch_async(dispatch_get_main_queue(), ^{
        [self.manager downloadWithURL:clothes.url options:SDWebImageLowPriority progress:^(NSUInteger receivedSize, long long expectedSize) {
            CGFloat domandeFloat = [[NSNumber numberWithInteger:receivedSize]floatValue];
            CGFloat corretteFloat = [[NSNumber numberWithLongLong:expectedSize] floatValue];
            float currentProgress = domandeFloat/corretteFloat;
                 [weakCell.circleProgressBar setProgress:currentProgress animated:YES];
        } completed:^(UIImage image, NSError error, SDImageCacheType cacheType, BOOL finished) {
            if(image){
                weakCell.imageViewCloth.image=image;
                weakCell.imageViewCloth.clipsToBounds = YES;
                weakCell.imageViewCloth.layer.borderWidth = 1.0;
                weakCell.imageViewCloth.layer.borderColor = [UIColor blackColor].CGColor;
                [weakCell.circleProgressBar setProgress:1 animated:YES];
            }
        }];

});
    //[weakCell.imageViewCloth setImageWithURL:clothes.url];

        return weakCell;
}

我已经尝试过这段代码,但当我向上和向下滚动时遇到了问题。它 使用相同的单元格。

【问题讨论】:

    标签: ios iphone progress-bar lazy-loading uicollectionviewcell


    【解决方案1】:

    首先,您应该找到一个您将要使用或构建自己的圆形进度条。我通常使用以下选项之一:

    1. 使用 CALayer,使用 drawRect 绘制进度,使用动画制作进度 使用Facebook POP 的动画变量;
    2. 使用 CAShaperLayer 并为 strokeEnd 设置动画。

    要使其正常工作,您至少应该:

    1. 通知所有可见单元格您下载的项目的进度已更改,并将新进度仅设置到所需单元格;
    2. 开启- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 预填充进度。

    herehere 已经提出过这个问题。

    我做了一点研究,发现了这个:XLRemoteImageView。值得一看。感谢xmartlabs

    【讨论】:

    • 感谢您的回答,但如果您有相关代码,请提供给我..plz。
    • 关于如何进行进度或如何下载文件?在我在回答中引用的链接中,您可以找到有关如何在进度更改时更新单元格的代码示例。
    • 我的要求就像在带有百分比进度条的collectionview单元格中延迟加载图像
    • 我已经更新了我的答案,看看XLRemiteImageView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多