Last active
October 16, 2019 05:39
-
-
Save SongJiaqiang/a6f709c2f12a6e0a73a7db6583a70a4d to your computer and use it in GitHub Desktop.
保存gif到相册
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AssetsLibrary | |
import MobileCoreServices | |
/// 保存gif图到相册 | |
func saveGif2Album() { | |
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif") | |
let gifData = NSData(contentsOfFile: gifPath!) as Data | |
let library = ALAssetsLibrary() | |
library.writeImageData(toSavedPhotosAlbum: gifData, metadata: nil, completionBlock: { (assetURL, error) in | |
DispatchQueue.main.async { | |
Toast.show(message: "gif图已保存到相册") | |
} | |
}) | |
} | |
/// 拷贝gif到粘贴板 | |
func copyGif2Pasteboard() { | |
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif") | |
let gifData = NSData(contentsOfFile: gifPath!) as Data | |
UIPasteboard.general.setData(gifData, forPasteboardType: kUTTypeGIF as String) | |
Toast.show(message: "gif图已拷贝到粘贴板") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment