原生 iOS Twitter 组件不支持 GIF。如果需要发布 GIF,这个组件会很有帮助。
尽管这个项目不依赖于 FLAnimatedImage,但与它的配合会更好。
class ViewController: UIViewController, TwitterGifComposerDelegate {
/* ... */
@IBAction func touchUpInside(sender: AnyObject) {
var path = NSBundle.mainBundle().pathForResource("abc", ofType: "gif")
var data = NSData(contentsOfFile: path!)
self.twitterGifComposer = TwitterGifComposer.defaultComposer(delegate: self, rootViewController: self).withText("Post Gif").withGifData(data!)
/*
The image view in composer only show static image, by default.
But if FLAnimatedImage is also imported, you can replace it as FLAnimatedImageView
*/
var animatedImageView = FLAnimatedImageView(frame: CGRectZero)
animatedImageView.animatedImage = FLAnimatedImage(GIFData: data!)
animatedImageView.startAnimating()
self.twitterGifComposer!.attachFLAnimatedImageView(animatedImageView)
/* show the composer */
self.twitterGifComposer!.show()
}
func onPostFailed() { }
func onPostSuccessed() { }
func onStopPost() { }
iOS 8.0
TwitterGifComposer 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod "TwitterGifComposer"
zh-wang, [email protected]
TwitterGifComposer 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。