swiftgif / swiftgif Goto Github PK
View Code? Open in Web Editor NEW[UNMAINTAINED] ๐ A small UIImage extension with gif support
License: MIT License
[UNMAINTAINED] ๐ A small UIImage extension with gif support
License: MIT License
Hi, stopAnimating() is not working for me? I use Swift 3 on xcode 8. So basically the stopAnimating call does have no effect and gif continues to loop and loop.
Please see: How to pause temporarily the gif? #41 for context.
Thanks.
Hello, anyone having any problems loading named .gif? My code is the same as it was before moving to Swift 3.0 and XCode 8 but I can no longer see the .gif playing.
I have updated the SwiftGif to its latest version.
Any ideas?
I've imported the files and it works just fine with the demo gifs provided but when I load in a 3.9mb 640x400 gif the gif lags and the memory of the device (running in simulator) reaches 223mb, this seems exceedingly high.
Is there a limit for the gif that I'm using that I should take in account?
i have download the list of gif from server into my document directory.
now when i m going to display it crash.
mycode:
let imageData = NSData(contentsOfURL: NSURL(fileURLWithPath: dataPath))
let advTimeGif = UIImage.gifWithData(imageData!)
Crash at here::
var delayObject: AnyObject = unsafeBitCast(
CFDictionaryGetValue(gifProperties,
unsafeAddressOf(kCGImagePropertyGIFUnclampedDelayTime)),
AnyObject.self)
when i use it in viewDidLoad Or viewWillAppear myImg.loadGif(name: "GifImgName") this error occur :
Message from debugger: Terminated due to memory issue
#31 What is the resolution for this issue?
Hi, trying to load invalid data as a GIF crashes this code with EXC_BAD_ACCESS. This is due to the unsafe code in delayForImageAtIndex(). Proper checks should be in place and the UIImage.gifWithData() should throw / return nil if invalid data was handed in.
As a quick hack, the following is how I made this 'work' (= not crash):
class func delayForImageAtIndex(index: Int, source: CGImageSource!) -> Double {
var delay = 0.1
guard let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil) as? NSDictionary,
gifProperties = cfProperties[kCGImagePropertyGIFDictionary as NSString] as? NSDictionary else {
return delay
}
var delayTime = gifProperties[kCGImagePropertyGIFUnclampedDelayTime as NSString]
if delayTime?.doubleValue == 0.0 {
delayTime = gifProperties[kCGImagePropertyGIFDelayTime as NSString]
}
if let delayTime = delayTime {
delay = delayTime.doubleValue
}
if delay < 0.1 {
delay = 0.1 // Make sure they're not too fast
}
return delay
}
Also, building for the device, I get the linker error:
ld: framework not found SwiftGifOrigin for architecture arm64
Hey guys,
I'm new to ios development, but using 1.6 in my podfile didn't work so I checked the specs repo to see if its listed and the last spec listed is 1.5.3
https://github.com/CocoaPods/Specs/tree/master/Specs/SwiftGifOrigin
Hey,
There are couple of errors while building on Xcode 8 GM. Could you please fix it and patch an update?
Thanks :)
I'm using the latest Xcode 9, and when I tryed to run my application I get the error This image named "nav" does not exist, I tryed to use this in Xcode 8 without any problems.
Any idea how to fix this problem?
Is there a way to adjust the speed of the animation? Awesome work BTW.
Hi,
it would be nice to have the library in CocoaPods (right now I've added it using Peru https://github.com/buildinspace/peru).
BTW, I love the demo gif in the readme ;)
Any chance you could add this to Cocoa Pods please, for easy installation into projects?
func delayForImageAtIndex line 74:
if delayObject.doubleValue == 0 {
delayObject = unsafeBitCast(CFDictionaryGetValue(gifProperties,
unsafeAddressOf(kCGImagePropertyGIFDelayTime)), AnyObject.self)
}
will cause the issues when there is only single frame
i'am newbie to swift, i add this code to fixed the issues. but i don't know whether this is a good way or not.
if count == 1 {
return UIImage(CGImage: CGImageSourceCreateImageAtIndex(source, 0, nil)!)
}
When running the tests in Xcode6-Beta5, they fail when trying to load the test gif:
let cfImageData = imageData! as CFDataRef
Throws fatal error: unexpectedly found nil while unwrapping an Optional value
; this looks to be caused by
imageData = NSData(contentsOfURL: NSBundle.mainBundle().URLForResource("test", withExtension: "gif"))
Returning nil. I've tried various ways of loading images, but can't seem to get the resources to load (UIImage named etc all fail).
Thanks for the awesome library!
Is there any public property to set the repeat count for the gif image? I want the gif image to animate just once.
Oh, sorry, I just confound Your lib with another :) Anyway I was using Your lib, but it is memory inefficient. Better way is to allocate i.e. 5 frames in memory as cache and prepare another in runtime.
Good luck!
Hey,
Just wanted to know if you're planning to update it for Swift3 or if it's abandonned ! So I can look for another third party option ! It would be a shame, it's the more practical and the lightest one !
I cannot install SwiftGif for swift3.
My Podfile is ..
pod 'SwiftGifOrigin', '~> 1.6'
But I get the following error.
Analyzing dependencies
[!] Unable to satisfy the following requirements:
- `SwiftGifOrigin (~> 1.6)` required by `Podfile`
- `SwiftGifOrigin (~> 1.6)` required by `Podfile`
None of your spec sources contain a spec satisfying the dependency: `SwiftGifOrigin (~> 1.6)`.
You have either:
* out-of-date source repos which you can update with `pod repo update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
I run pod repo update
, but I get the same error again.
How can I use SwiftGif??
Getting
SwiftGif: This image named "njoy" does not exist
while trying
I noticed that when I add a gif to the scene, the CPU usage remains stable but when I press the home button and reopen the app, the % jumps from around 15% to 50-60%. This even happens on the demo app.
Does this happen for anyone else? If so, any fixes for it?
Hello! would be good you could add support for swift 5.0
After upgrading to Xcode 8.3, I'm getting a compilation error on the method declaration for gif(_ url: String)
that says
Method 'gif' with Objective-C selector 'gif:' conflicts with previous declaration with the same Objective-C selector
And also on gif(_ name: String)
I'm getting another error that says
Invalid redeclaration of 'gif'
Seems straightforward since Objective-C doesn't support method overloading and the class is extending the Objective-C class UIImage. Just wondering why this wasn't an issue before the upgrade.
adding the following to my Cartfile
github "bahlo/SwiftGif"
results is the following:
*** Skipped building SwiftGif due to the error:
Dependency "SwiftGif" has no shared framework schemes for any of the platforms: iOS
Hi, the gif is animating properly but when I try to resize the image to fit the screen width, the gif is not animating. Here's the code:
/* IMAGEVIEW */
var silvester: UIImage = UIImage.gifWithName("image")!
let screenW: CGFloat = UIScreen.mainScreen().bounds.size.width
let imageH: CGFloat = screenW / 1.3
let sizeRight : CGSize = CGSize(width: screenW, height: imageH)
silvester = scaleUIImageToSize(silvester, size: sizeRight)
bgImage = UIImageView(image: silvester)
self.view.addSubview(bgImage!)
/* SCROLLVIEW */
self.scrollView = UIScrollView(frame: view.bounds)
self.scrollView.backgroundColor = UIColor.blackColor()
scrollView.contentSize = bgImage.bounds.size
scrollView.autoresizingMask = UIViewAutoresizing.FlexibleWidth
scrollView.autoresizingMask = UIViewAutoresizing.FlexibleHeight
scrollView.addSubview(bgImage)
view.addSubview(scrollView)
scrollView.delegate = self
And here is the function I use to scale the UIImage:
func scaleUIImageToSize(let image: UIImage, let size: CGSize) -> UIImage {
let hasAlpha = false
let scale: CGFloat = 0.0 // Automatically use scale factor of main screen
UIGraphicsBeginImageContextWithOptions(size, !hasAlpha, scale)
image.drawInRect(CGRect(origin: CGPointZero, size: size))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return scaledImage
}
What's the problem?
Thanks.
I know I'm doing something wrong but don't know what.
I have a gif spinner at 30fps, but it plays about half as slow as the gif.
Does anyone have this issue?
Here is the original gif, but when played on the device it's slower
When played on device:
Hi,
I created a custom UITableViewCell with UIImageView inside to display the gifs in a TableView, but scrolling the TableView is slow, laggy and get stuck for a few seconds while trying to scroll. What can I do?
Thanks.
Is it possible to transfer and start animation from current frame in another ViewController? For example if i have i bird flying from a left border and then suddenly i need to transit through segue to another view controller may i have the same position of the bird on another without it being reset to the beginning of animation?
I'm having issues trying to get the animation to stop after the first loop
is there a way to do this?
thanks in advance
I need only one cycle animating, how do to this?
Once i run my app in the debug terminal it shows this -
"SwiftGif: Cannot turn image named "battery" into NSDataAsset"
how to solve this problem?
Thanks in advance.
I have a gif which I am running for one cycle of animation. Once the animation is completed, I want to freeze the last animation image on my imageView. How can I achieve that?
let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil)
is giving an error =
"Cannot invoke 'CGImageSourceCopyPropertiesAtIndex' with an argument list of type 'CGImageSourceRef,Uint,nil)'
Do you think it is possible to add a function where you could pause/play the gif at the current frame?
If a gif has a high framerate where the delay is < 0.1 sec, the delay defaults to 0.1 sec.
Hi!
Can i use this framework with storyboard without any code? I want to present gif in LaunchScreen.storyboard
file. Thanks!
If possible, it would be nice to have a .restart()
function. Thanks!
When it try to open a gif with url (UIImage.gif(url: "www.exampleurl.com/test.gif")) i always get the same message back: Cannot turn image named "www.exampleurl.com/test.gif" into NSData
Does anyone else has the same problem?
thank you for making this. The code works with no modifications on tvOS however the podfile can't install it due to the spec not offering the tvOS.
Could you add it?
thx!
This would be good
Pretty straight forward: does not work within extensions (eg Keyboard).
I programmatically added a gif in a stackview, however, the image is not animating
"display_url" = "pic.twitter.com/PD4fxB83OI";
"expanded_url" = "https://twitter.com/MarcAnthony/status/836026935813746688/photo/1";
"media_url" = "http://pbs.twimg.com/tweet_video_thumb/C5oqDsuXQAAEEcm.jpg";
Can my gif save in cache. I load a gif from url in a uiimageview in collectionviewcell. And when I scroll down, then up. I see it has to load again.
Hi Bahlo, I've just took a look on your library. Everything works amazingly, but I am in stuck with a problem. How to pause temporarily the gif? I want pause and resume it for some reason (like music play, pause...)
Thanks very much and wait for your reply.
i just cant load anything ,,
xcode :Version 9.0 (9A235)
// jeremy.gif
var url = NSBundle.mainBundle().URLForResource("jeremy", withExtension: "gif")
var imageData = NSData(contentsOfURL: url)
// Returns an animated UIImage
UIImage.animatedImageWithData(imageData)
This uses too many lines to setup the gif. It could have been only:
UIImage.withGifName("jeremy")
I might do this in the future when I have time
Hello,
When I pull the framework with a carthage update (github "bahlo/SwiftGif" ~> 1.6.1), I can import it normally with "import SwiftGif" but I can't access to any methods of it...
Am I doing wrong or it's a framework issue?
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.