UITableView seems getting little bit stuck during vertical scroll

99 Views Asked by At

Converting downloaded image with rounded corners inside table view cell. Regarding image downloading process, used SDWebImage and making rounded corners inside completion block. So this reason feeling stuck issue during vertical scroll. Is their need any dispatch to over come that sticky issue for achieve smooth scrolling...

    func circularImage(size: CGSize?) -> UIImage? {
        let newSize = size ?? self.size
        
        let minEdge = min(newSize.height, newSize.width)
        let size = CGSize(width: minEdge, height: minEdge)
        
        UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
        let context = UIGraphicsGetCurrentContext()
        
        self.draw(in: CGRect(origin: CGPoint.zero, size: size), blendMode: .copy, alpha: 1.0)
        
        context?.setBlendMode(.copy)
        context?.setFillColor(UIColor.clear.cgColor)
        
        let rectPath = UIBezierPath(rect: CGRect(origin: CGPoint.zero, size: size))
        let circlePath = UIBezierPath(ovalIn: CGRect(origin: CGPoint.zero, size: size))
        rectPath.append(circlePath)
        rectPath.usesEvenOddFillRule = true
        rectPath.fill()
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return result
    }

And Inside the tableview cell.

   if let thumbImageUrlUW = valueUW.thumbImageUrl {
                    UIImageView().sd_setImage(with: URL(string: thumbImageUrlUW)) { (thumbImage, _, _, _) in
                        if let thumbImageUW = thumbImage, let roundedThumbImage = thumbImageUW.circularImage(size: imageSize) {
                            valueUW.thumbImage = roundedThumbImage
                            colorsUW.remove(at: index)
                            colorsUW.insert(valueUW, at: index)
                        }
                    }
                }

ProductDetailsInsideTableViewCell

UIAction with details

1

There are 1 best solutions below

0
StackOverflowEnjoyer On

As a rule of thumb, any kind of operation between having some representation of data and a final UIImage object should be done on some background thread.

So in your case I'd make sure I am running all of my manipulations on a background thread and only switch back to the main thread once I am ready to pass it on or assign it to a UIImageView.