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