Copy GIF to UIPboardboard

I am trying to copy a GIF image to a UIP archive in swift, at the moment it only copies the static version of the image and seems to convert it to PNG, looking at the file extension when I upload it somewhere.

Interestingly, did anyone know how to achieve this? All the other fixes that I found seem to work only when retrieving NSData from the url and not from the bundled image

+7
ios cocoa swift gif uipasteboard
source share
2 answers

For those who have ever encountered this problem, I managed to find a solution

let url: NSURL = NSBundle.mainBundle().URLForResource("\(self.imageNames[indexPath.row])", withExtension: ".gif")! let data: NSData = NSData(contentsOfURL: url)! UIPasteboard.generalPasteboard().setData(data, forPasteboardType: "com.compuserve.gif") 

As it turns out, you need to use the URL and extract the NSData from the GIF from that URL.

Here I get the GIF URL that is in my package, looking for it using the name and image extension. Then I set the data in the file cabinet and bingo, we have an animated GIF when inserting the result from cardboard

+7
source share

It doesn't seem that the image property on the file cabinet supports the GIF type.

A related array of view types is UIPasteboardTypeListImage, which includes the kUTTypePNG and kUTTypeJPEG types.

Perhaps you could do this using NSData from GIF:

 import MobileCoreServices // ... var image = UIImage(...) let data = NSData(bytes: &image, length: sizeof(UIImage)) UIPasteboard.generalPasteboard().setData(data, forPasteboardType: kUTTypeGIF as String)) // com.compuserve.gif 
+1
source share

All Articles