alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
2.02k stars 212 forks source link

Gif animations play at different speeds on iPad vs iPhone #125

Closed RoboWorldEnt closed 3 years ago

RoboWorldEnt commented 4 years ago

Hello all,

I've been loving SwiftyGif so far. When we implemented it, we noticed gif animations are playing at different speeds on iPad vs iPhone. Here's a few videos to showcase what I mean:

iPad: https://trello-attachments.s3.amazonaws.com/5d8d55c6edf1901a536c38c8/5dc185b8b25a342a77c24f2e/4e2fd05eb07a1254ec5ed1179648e0b1/ipad-gifplayback.mp4

iPhone: https://trello-attachments.s3.amazonaws.com/5d8d55c6edf1901a536c38c8/5dc185b8b25a342a77c24f2e/029961d6a5990c416ee0b79830e511a3/iPhone_gif_playback.mp4

Any ideas about how to fix this?

alexiscreuzot commented 4 years ago

The error might be around here : https://github.com/kirualex/SwiftyGif/blob/master/SwiftyGif/UIImage%2BSwiftyGif.swift#L207-L215

Could you try changing : let displayRefreshFactors = [60, 30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1] to let displayRefreshFactors = [30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1]

shliama commented 4 years ago

@kirualex tried that, didn't help - still get ~2x GIF speed on iPad Pro (11-inch) iOS 13.7.

alfiewm commented 4 years ago

Same problem on iPad Pro, gif plays abnormally faster.

Tried add 120 to displayRefreshFactors and works. let displayRefreshFactors = [120, 60, 30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1]

It might be related to the 120HZ refresh rate on iPad pro?

amberreyn commented 3 years ago

I'm having the same problem. What's the best workaround?

shliama commented 3 years ago

@amberreyn I've ended up using simple WebView (my case is onboarding screen, with a single looping animation) with SwiftUI like so:

WebView(url: Bundle.main.url(forResource: "fox.gif", withExtension: nil)!)
                    .frame(width: 240, height: 240)
mattcomi commented 3 years ago

Submitted a PR that fixes this: https://github.com/kirualex/SwiftyGif/pull/150