gpt4 book ai didi

ios - 使用 SDWebImage block 的 ImageView 上的圆形进度条

转载 作者:行者123 更新时间:2023-12-01 16:09:19 24 4
gpt4 key购买 nike

我正在尝试使用 SDWebImage 实现一个类似圆形进度条的 instagram 来加载图像。
1.我正在使用这段代码,但它不能正常工作。将图像应用于 ImageView 后,进度条不会隐藏。

  • 单元重用问题也引起了一些问题。
  • 还会发出警告,提示我正在尝试更新后台线程中的进度条。

  • 我怎样才能摆脱这些问题
    - (void)setImageInImageView:(UIImageView *)imgv withURLString:(NSString *)str_url {

    //GuestDefaultProfilePic
    [imgv sd_setImageWithURL:[NSURL URLWithString:str_url] placeholderImage:[UIImage imageNamed:@"ImageGalleryBackground"] options: SDWebImageHighPriority progress:^(NSInteger receivedSize, NSInteger expectedSize){

    NSLog(@"the progress is %f", ((receivedSize*1.0f) * 100) / expectedSize);
    progressView = [imgv viewWithTag:4321];

    if(progressView==nil)
    {
    progressView = [[THCircularProgressView alloc] initWithFrame:CGRectMake(imgv.center.x - 20 , imgv.center.y-20 , 60 , 60)];
    progressView.lineWidth = 5.0f;
    progressView.progressColor = [UIColor whiteColor];
    progressView.progressBackgroundColor = [UIColor grayColor];

    progressView.centerLabelVisible = YES;
    progressView.tag = 4321;
    [imgv addSubview:progressView];
    }

    dispatch_async(dispatch_get_main_queue(), ^{
    [progressView setPercentage:(receivedSize*1.0f) / expectedSize];
    });
    if(receivedSize >= expectedSize)
    {
    progressView.hidden = YES;
    }
    }
    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){

    [progressView setHidden:YES];
    [progressView removeFromSuperview];
    [progressView setPercentage:0];
    [imgv setImage:image];

    }];


    }

    最佳答案

    你可以试试这个

  • 安装 pod "MBCircularProgressBar"
  • 将 UIView 放在您的自定义单元格上,就像您想要进度 View 并设置类 MBCircularProgressBarView 一样。
    @IBOutlet weak var progressView: MBCircularProgressBarView!


    cell.imgAlbum.sd_setImage(with: URL(string: imageUrl), placeholderImage: UIImage(named: "placeholderImage"), options: .highPriority, progress: { (receivedSize :Int, ExpectedSize :Int, url:URL?) in

    DispatchQueue.main.async {
    cell.ActivityView.isHidden = false;
    cell.ActivityView.value = CGFloat(receivedSize)
    cell.ActivityView.maxValue = CGFloat(ExpectedSize)
    }
    }) { (image : UIImage?, error : Error?, cacheType : SDImageCacheType?, url:URL?) in

    DispatchQueue.main.async {
    UIView.animate(withDuration: 3.0, animations: {() -> Void in
    cell.ActivityView.isHidden = true;
    })}

    cell.imgBlur.removeBlurEffect()
    }
  • 关于ios - 使用 SDWebImage block 的 ImageView 上的圆形进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33370501/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com