我假设您使用的是https://github.com/mayoff/uiimage-from-animated-
gif,
+UIImageanimatedImageWithAnimatedGIFdata:源代码在Objective-C中。
您首先需要将Objective-C标头导入Swift。 将Swift与Cocoa和Objective-
C结合使用
说明了如何做到这一点:
要在与Swift代码相同的框架目标中导入一组Objective-C文件,您需要将这些文件导入框架的Objective-C伞形标头中。
从同一框架将Objective-C代码导入Swift
- 在“打包设置”下的“构建设置”下,确保该框架目标的“定义模块”设置被设置为“是”。
- 在您的伞形头文件中,导入要公开给Swift的每个Objective-C头。例如:
#import "UIImage+animatedGIF.h"
然后,您可以
testImage按照以下步骤进行设置:
var testImage = UIImage.animatedImageWithAnimatedGIFData( NSData.dataWithContentsOfURL(url))self.dataImageView.animationImages = testImage.imagesself.dataImageView.animationDuration = testImage.durationself.dataImageView.animationRepeatCount = 1self.dataImageView.image = testImage.images.lastObjectself.dataImageView.startAnimating()



