How to play gif in widget?

How to play gif in widget? "网易云音乐" and "one widget" can play gif in the widget. can anyone guide me. Thank you

Post not yet marked as solved Up vote post of fwzhou Down vote post of fwzhou
2.9k views

Replies

Well, what have you tried? What code are you trying to use that isn't working? I mean, I'll just say use: Image("myImage.gif"). Does that work?

  • Thank you for your reply. I used Timer and CADisplayLink, but in the widget, these timers are "invalidated". The method you mentioned can only display the first frame. Image(uiImage: UIImage(named: "animated.gif")!) Through the bridge of UIViewRepresentable, WKWebView or UIImageView can load gif, but the view after handover will not be displayed. This method ._clockHandRotationEffect(.secondHand, in: .current, anchor: .center) can rotate images, but it has been disabled in Xcode 14.

  • Thank you for your reply. I tried Timer and CADisplayLink, but they are all "invalid" in the widget. Image can be rotated by _clockHandRotationEffect(.secondHand, in: .current, anchor: .center), but it has been disabled in Xcode 14. For the method you mentioned, Image (uiImage: UIImage (contentsOfFile: "animated. gif")) can only display the first frame.

  • Thank you for your reply. I tried Timer and CADisplayLink, but they are all "invalid" in the widget. Image can be rotated by clockHandRotationEffect(.secondHand, in: .current, anchor: .center), but it has been disabled in Xcode 14. For the method you mentioned, Image (uiImage: UIImage (contentsOfFile: "animated. gif")) can only display the first frame.

Thank you for your reply. I tried Timer and CADisplayLink, but they are all "invalid" in the widget. Image can be rotated by _clockHandRotationEffect(.secondHand, in: .current, anchor: .center), but it has been disabled in Xcode 14. For the method you mentioned, Image (uiImage: UIImage (contentsOfFile: "animated. gif")) can only display the first frame. @darkpaw

Hello, I also have the same problem, have you found a solution?

Add a Comment

你好,我也遇到了同样的问题,请问你找到解决办法了吗?

  • 没有找到

Add a Comment

没有找到解决方案@past

You may find success using a custom font which contains your own glyphs and a SwiftUI timer which would essentially swap your characters on each invocation (each second). Apple does not provide native support for .gif. The closest thing would be an .apng but those would not work in Widgets either.

Hello, I also have the same problem, have you found a solution? ClockHandRotationKit not working on iOS 13