简体   繁体   English

如何在不使用第三方库的情况下在Xamarin.iOS中将gif与UIImageView一起使用?

[英]How to use gif with UIImageView in Xamarin.iOS without using third party library?

I want to load gif image in UIImageView. 我想在UIImageView中加载gif图像。 I've try to use it wih FLAnimatedImage but it not worked. 我尝试将其与FLAnimatedImage一起使用,但无法正常工作。 I have taken imageview in storyboard and added gif to resources. 我已经在情节提要中使用了imageview并将gif添加到资源中。

If you want to load gif image with UIImageView, I find one article that you can take a look: 如果要使用UIImageView加载gif图像,我会找到一篇文章,您可以看一下:

https://montemagno.com/animated-gif-uiimageview-in-xamarinios/ https://montemagno.com/animated-gif-uiimageview-in-xamarinios/

If you try to create the gif using individual images, it will be easier, as you can see here. 如果您尝试使用单个图像创建gif,则将变得更加容易,如您在此处看到的。 When you convert the native code from here to C#, you get this 当您将本地代码从此处转换为C#时,您会得到

UIImageView gifView = new UIImageView();
gifView.AnimationImages = new UIImage[] {
    UIImage.FromBundle("Image1.png"),
    UIImage.FromBundle("Image2.png"),
    UIImage.FromBundle("Image3.png"),
    UIImage.FromBundle("Image4.png")
};
gifView.AnimationRepeatCount = 0; // Repeat forever.
gifView.AnimationDuration = 1.0; // Every 1s.
gifView.StartAnimating();
gifView.View.Frame = new CoreGraphics.CGRect(0, 20, this.View.Bounds.Size.Width, 180); // size of the animation
this.View.AddSubview(gifView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM