-
-
Save solos/8188f3e3c7d639d63f176eba4c5821e9 to your computer and use it in GitHub Desktop.
保存gif到相册
This file contains 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