Post

Replies

Boosts

Views

Activity

Reply to SwiftUI: How to blend between UIImages without pulsating/pumping effect?
There is no problem with the phase animator. If I do this struct ContentView: View { @State var img1 = UIImage(systemName: "gear")! @State var img2 = UIImage(systemName: "gear")! var body: some View { PhaseAnimator([1, 2]) { phase in Image(uiImage: phase == 1 ? img1 : img2) .renderingMode(.template) .foregroundStyle(.white) .background(.black) } } } It exactly does blend as expected. It blends two images (with identical content) and you will not see a pumping effect. The problem starts, when I create an UIImage with UIGraphicsBeginImageContext like with the resize function in my first post. Then the two identical images are pulsating. PhaseAnimator([1, 2]) { phase in Image(uiImage: phase == 1 ? img1 : img2) .renderingMode(.template) .foregroundStyle(.white) .background(.black) } .task { img1 = self.resizeImage(image: img1, newWidth: widgetSize) img2 = self.resizeImage(image: img2, newWidth: widgetSize) } (And yes, UIGraphicsBeginImageContext is deprecated, but it does not matter, the same behaviour can be observed using UIGraphicsImageRenderer)
Jul ’24