You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Resizing an UIImageView via UIViewPropertyAnimator makes loaded image disappear and placeholder appear. Only happens when image is not cached. I'm attaching sample code and a screen recording.
Reproduce
//// ViewController.swift// KingFisherResizing//// Created by Martin Pittenauer on 16.02.24.//
import UIKit
import Kingfisher
classViewController:UIViewController{private lazy varimageView:UIImageView={letimageView=UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode =.scaleAspectFill
imageView.clipsToBounds = true
return imageView
}()
lazy varwidthConstraint:NSLayoutConstraint={ imageView.widthAnchor.constraint(equalToConstant:200)}()overridefunc viewDidLoad(){
super.viewDidLoad()// Do any additional setup after loading the view.
view.addSubview(imageView)NSLayoutConstraint.activate([
imageView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
imageView.topAnchor.constraint(equalTo: view.topAnchor),
imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier:9/16),
widthConstraint
])letimageUrl=URL(string:"https://res.cloudinary.com/dg-stage/image/fetch/w_2642/https://dg-stage-production-pictures.s3.eu-west-1.amazonaws.com/be9e66cd3f8fc57d008b5969ad87ce04c385bbbe.jpg?_a=AEABoAB0")!
letplaceholder=UIImage(named:"placeholder")
imageView.kf.setImage(with: imageUrl, placeholder: placeholder, options:[.transition(.fade(0.4)),.forceRefresh])startTimer()}varfraction:Double= 0.0
varchange:Double= 0.02
vartimer:Timer?varanimator:UIViewPropertyAnimator?func startTimer(){
widthConstraint.constant =900
animator =UIViewPropertyAnimator(duration: 1.0, curve:.easeInOut){[weak self]inself?.view.layoutIfNeeded()}
animator?.pauseAnimation()
timer =Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true){[weak self] _ in
guard let self else{return}
if self.fraction <=0{
change = 0.02
}
if self.fraction >=1{
change =-0.02
}self.fraction =self.fraction + change
animator?.fractionComplete =self.fraction
}}}
The text was updated successfully, but these errors were encountered:
This is caused by the UIView.transition used by Kingfisher in makeTransition() still being part of the UIImageView and being triggered in reverse. It needs to be removed after it is finished. Unfortunately it seems UIViewPropertyAnimator captures it and prevents it from being removed automatically.
A hacky workaround that seems to work is:
imageView.kf.setImage(with: imageUrl, placeholder: placeholder, options:[.transition(.fade(0.4)),.forceRefresh,.waitForCache]){ _ in
if let keys =self.layer.animationKeys(), keys.contains("contents"){self.imageView.layer.removeAnimation(forKey:"contents")}}
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
Issue Description
What
Resizing an UIImageView via UIViewPropertyAnimator makes loaded image disappear and placeholder appear. Only happens when image is not cached. I'm attaching sample code and a screen recording.
Reproduce
The text was updated successfully, but these errors were encountered: