{"id":13379277,"url":"https://github.com/kaishin/Gifu","last_synced_at":"2025-03-13T05:30:52.452Z","repository":{"id":20493579,"uuid":"23771864","full_name":"kaishin/Gifu","owner":"kaishin","description":"High-performance animated GIF support for iOS in Swift","archived":false,"fork":false,"pushed_at":"2025-01-20T20:23:33.000Z","size":26702,"stargazers_count":3141,"open_issues_count":29,"forks_count":287,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-03-11T20:15:05.405Z","etag":null,"topics":["animation","carthage","cocoapods","gif","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaishin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"Supporting Files/Info.plist","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-07T21:46:51.000Z","updated_at":"2025-03-10T15:50:00.000Z","dependencies_parsed_at":"2023-02-19T04:15:39.623Z","dependency_job_id":"d6f32a78-ed09-4fc5-bc18-54683ee275fd","html_url":"https://github.com/kaishin/Gifu","commit_stats":{"total_commits":182,"total_committers":31,"mean_commits":5.870967741935484,"dds":0.6043956043956045,"last_synced_commit":"82da0086dea14ca9afc9801234ad8dc4cd9e2738"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaishin%2FGifu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaishin%2FGifu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaishin%2FGifu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaishin%2FGifu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaishin","download_url":"https://codeload.github.com/kaishin/Gifu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243351001,"owners_count":20276893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","carthage","cocoapods","gif","swift"],"created_at":"2024-07-30T07:02:26.390Z","updated_at":"2025-03-13T05:30:52.445Z","avatar_url":"https://github.com/kaishin.png","language":"Swift","funding_links":[],"categories":["Swift","swift"],"sub_categories":[],"readme":"# ![Logo](https://github.com/kaishin/Gifu/raw/master/header.gif)\n\n![Test](https://github.com/kaishin/Gifu/workflows/Test/badge.svg)\n[![GitHub release](https://img.shields.io/github/release/kaishin/Gifu.svg)](https://github.com/kaishin/Gifu/releases/latest) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg) ![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20tvOS-lightgrey.svg)\n\nGifu adds protocol-based, performance-aware animated GIF support to UIKit. (It's also a [prefecture in Japan](https://goo.gl/maps/CCeAc)).\n\n## Install\n\n#### Swift Package Manager\n\nAdd the following to your `Package.swift` file:\n\n```swift\nlet package = Package(\n    dependencies: [\n    .package(url: \"https://github.com/kaishin/Gifu.git\", from: \"3.2.2\")\n    ],\n)\n```\n\n#### [Carthage](https://github.com/Carthage/Carthage) (Deprecated)\n\n- Add the following to your Cartfile: `github \"kaishin/Gifu\"`\n- Then run `carthage update`\n- Follow the current instructions in [Carthage's README][carthage-installation]\n  for up to date installation instructions.\n\n[carthage-installation]: https://github.com/Carthage/Carthage#adding-frameworks-to-an-application\n\n#### [CocoaPods](http://cocoapods.org) (Deprecated)\n\n- Add the following to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html): `pod 'Gifu'`\n- You will also need to make sure you're opting into using frameworks: `use_frameworks!`\n- Then run `pod install` with CocoaPods 0.36 or newer.\n\n\u003e **Deprecated Methods Notice**: The installation methods using Carthage and CocoaPods are now deprecated and will not be supported in future releases. It is recommended to use Swift Package Manager for integrating Gifu into your projects.\n\n## How It Works\n\n`Gifu` does not require using the built-in `GIFImageView` subclass. The `Animator` class does the heavy-lifting, while the `GIFAnimatable` protocol exposes the functionality to the view classes that conform to it, using protocol extensions.\n\nThe `Animator` has a `FrameStore` that only keeps a limited number of frames in-memory, effectively creating a buffer for the animation without consuming all the available memory. This approach makes loading large GIFs a lot more resource-friendly.\n\nThe figure below summarizes how this works in practice. Given an image\ncontaining 10 frames, Gifu will load the current frame (red), buffer the next two frames in this example (orange), and empty up all the other frames to free up memory (gray):\n\n\u003cimg src=\"https://github.com/kaishin/Gifu/raw/master/gifu-figure.gif\" width=\"300\" /\u003e\n\n## Usage\n\nThere are two options that should cover any situation:\n\n- Use the built-in `GIFImageView` subclass if you don't need to combine GIF support with another image library.\n- If you need more flexibility and composability, make your class conform to `GIFAnimatable`. In practice, any `UIView` subclass would do, since you get most of the required properties for free. For best results, make your `UIImageView` subclass conform to `GIFAnimatable` to get access to other features such as intrinsic content size.\n\n### GIFAnimatable\n\nThe bread and butter of Gifu. Through protocol extensions, `GIFAnimatable` exposes all the APIs of the library, and with very little boilerplate, any class can conform to it.\n\n```swift\nclass MyImageView: UIImageView, GIFAnimatable {\n  public lazy var animator: Animator? = {\n    return Animator(withDelegate: self)\n  }()\n\n  override public func display(_ layer: CALayer) {\n    updateImageIfNeeded()\n  }\n}\n```\n\nThat's it. Now `MyImageView` has access to all these methods and properties:\n\n- `prepareForAnimation(withGIFNamed:)` and `prepareForAnimation(withGIFData:)` to prepare the animator property for animation.\n- `startAnimatingGIF()` and `stopAnimatingGIF()` to control the animation.\n- `animate(withGIFNamed:)` and `animate(withGIFData:)` to prepare for animation and start animating immediately.\n- `frameCount`, `isAnimatingGIF`, and `activeFrame` to inspect the GIF view.\n- `prepareForReuse()` to free up resources.\n- `updateImageIfNeeded()` to update the image property if necessary.\n\nFurthermore, you can make any class GIF-animatable, starting with `UIView` subclasses:\n\n```swift\nclass CustomAnimatedView: UIView, GIFAnimatable {\n  public lazy var animator: Animator? = {\n    return Animator(withDelegate: self)\n  }()\n\n  override public func display(_ layer: CALayer) {\n    updateImageIfNeeded()\n  }\n}\n```\n\nYou can also make `UIKit` classes conform using associated objects may you wish:\n\n```swift\nimport UIKit\nimport Gifu\n\nextension UIImageView: GIFAnimatable {\n  private struct AssociatedKeys {\n    static var AnimatorKey = \"gifu.animator.key\"\n  }\n\n  override open func display(_ layer: CALayer) {\n    updateImageIfNeeded()\n  }\n\n  public var animator: Animator? {\n    get {\n      guard let animator = objc_getAssociatedObject(self, \u0026AssociatedKeys.AnimatorKey) as? Animator else {\n        let animator = Animator(withDelegate: self)\n        self.animator = animator\n        return animator\n      }\n\n      return animator\n    }\n\n    set {\n      objc_setAssociatedObject(self, \u0026AssociatedKeys.AnimatorKey, newValue as Animator?, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)\n    }\n  }\n}\n```\n\n### Examples\n\nThe simplest way to get started is initializing a `GIFAnimatable` class in code or in a storyboard, then calling `animate(:)` on it.\n\n```swift\nlet imageView = GIFImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 100))\nimageView.animate(withGIFNamed: \"mugen\") {\n  print(\"It's animating!\")\n}\n```\n\nYou can also prepare for the animation when the view loads and only start animating after a user interaction.\n\n```swift\n// In your view controller..\n\noverride func viewDidLoad() {\n  super.viewDidLoad()\n  imageView.prepareForAnimation(withGIFNamed: \"mugen\") {\n    print(\"Ready to animate!\")\n  }\n}\n\n@IBAction func toggleAnimation(_ sender: AnyObject) {\n  if imageView.isAnimatingGIF {\n    imageView.stopAnimatingGIF()\n  } else {\n    imageView.startAnimatingGIF()\n  }\n}\n```\n\nIf you are using a `GIFAnimatable` class in a table or collection view, you can call the `prepareForReuse()` method in your cell subclass:\n\n```swift\noverride func prepareForReuse() {\n  super.prepareForReuse()\n  imageView.prepareForReuse()\n}\n```\n\n### Demo App\n\nClone or download the repository and open `Demo/Demo.xcworkspace` to check out the demo app.\n\n## Documentation\n\nSee the [full API documentation](http://kaishin.github.io/Gifu/).\n\n## Compatibility\n\n- iOS 9.0+\n- Swift 4.0\n- Xcode 9.0\n\n## License\n\nSee LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaishin%2FGifu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaishin%2FGifu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaishin%2FGifu/lists"}