Play GIF pictures in IOS

Source: Internet
Author: User

Today, I suddenly think of their own project to use this piece, so I also tidied up a bit, save the spare, I downloaded a gif from the Internet pictures, take to test

Method One:// set location and size to play the picture on the WebView

CGRect Frame=cgrectmake (50, 50, 60,60);

Frame.size=[uiimage imagenamed:@ "Animation.gif"].size;


reading gif picture data

NSData *gif=[nsdata datawithcontentsoffile:[[nsbundle mainbundle]pathforresource:@ "animation" ofType:@ "gif"]; Find GIF images from inside the project

View Generation

UIWebView *webview=[[uiwebview alloc]initwithframe:frame];//web size is the size of the GIF

webview.userinteractionenabled=no;// User is not interactive

[WebView loaddata:gif mimetype:@ "Image/gif" Textencodingname:nil baseurl:nil];//to load the picture onto the WebView

[Self.view Addsubview:webview];

Method Two:

//2. Break a gif image into multiple png images and play with Uiimageview

uiimageview *gifimageview=[[uiimageviewalloc]initwithframe:cgrectmake (------);

    Nsarray*gifary=[NsarrayArraywithobjects:[UIImageImagenamed:@ "1"],[UIImageImagenamed:@ "2"],[UIImageImagenamed:@ "3"],[UIImageImagenamed:@ "4"],[UIImageImagenamed:@ "5"],[UIImageImagenamed:@ "6"],[UIImageImagenamed:@ "7"],[UIImageImagenamed:@ "8"],[UIImageImagenamed:@ "9"],[UIImageImagenamed:@ "Ten"],[UIImageImagenamed:@ "One"],[UIImageImagenamed:@ " a"],[UIImageImagenamed:@ "+"],[UIImageImagenamed:@ "+"],[UIImageImagenamed:@ " the"],[UIImageImagenamed:@ "+"],[UIImageImagenamed:@ "+"],[UIImageImagenamed:@ "@ "],Nil];

Gifimageview. animationimages=gifary; // animated Image Array

Gifimageview. animationduration=1; // the length of time required to perform a full animation

Gifimageview. Animationrepeatcount=0; // Animation Repeat number if it is 1, the animation will stop once, 0 repeats

[Gifimageview startanimating];//start animation

[Self. View addsubview: Gifimageview];


Tip: GIF animations must have the same interval between frames, otherwise it's not that smooth.



Play GIF pictures in IOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.