动画 – 如何在Swift中将gif显示到UIImageView中?
我想在UIImageView中使用gif,但我不能.
我的代码是: - (void)viewDidLoad { [super viewDidLoad]; NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"]; UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]]; self.dataImageView.animationImages = testImage.images; self.dataImageView.animationDuration = testImage.duration; self.dataImageView.animationRepeatCount = 1; self.dataImageView.image = testImage.images.lastObject; [self.dataImageView startAnimating]; } 迅速: var url : NSURL = NSBundle.mainBundle().URLForResource("MAES",withExtension: "gif") 在目标C中我有animatedImageWithAnimatedGIFData,但是在swift中我不知道如何调用这个或者如果不存在.. 谢谢!
我假设您正在使用
https://github.com/mayoff/uiimage-from-animated-gif for UIImage animatedImageWithAnimatedGIFData:并且源代码在Objective-C中.
您需要先将Objective-C标头导入Swift. Using Swift with Cocoa and Objective-C解释了如何执行此操作:
然后,您可以按如下方式设置testImage: var testImage = UIImage.animatedImageWithAnimatedGIFData( NSData.dataWithContentsOfURL(url)) self.dataImageView.animationImages = testImage.images self.dataImageView.animationDuration = testImage.duration self.dataImageView.animationRepeatCount = 1 self.dataImageView.image = testImage.images.lastObject self.dataImageView.startAnimating() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |