"IOS" shows gif motion on the page

Source: Internet
Author: User
Tags uikit

1- (void) Viewdidload2 {3 [Super Viewdidload];4     //Do any additional setup after loading the view.5     6     //1: Using third-party libraries7NSData *data = [NSData datawithcontentsoffile:[[nsbundle mainbundle] Pathforresource:@"Moe"OfType:@"gif"]];8Gifview *dataview = [[Gifview alloc] Initwithframe:cgrectmake ( -, -, -, -) Data:data];9 [Self.view Addsubview:dataview];Ten      One     //or AGifview *pathview =[[gifview alloc] Initwithframe:cgrectmake ( the, -, -, -) Filepath:[[nsbundle Mainbundle] Pathforresource:@"Moe"OfType:@"gif"]]; - [Self.view Addsubview:pathview]; -      the     //2: Using WebView -NSString *path = [[NSBundle mainbundle] Pathforresource:@"Moe"OfType:@"gif"]; -NSData *gifdata =[NSData Datawithcontentsoffile:path]; -UIWebView *webview = [[UIWebView alloc] Initwithframe:cgrectmake ( the, Max, -, -)]; +Webview.backgroundcolor =[Uicolor Clearcolor]; -Webview.scalespagetofit =YES; +[WebView loaddata:gifdata MIMEType:@"Image/gif"Textencodingname:nil Baseurl:nil]; A [Self.view Addsubview:webview]; at}

Third-party library code

 // //  //  Gifdemo  //  #import  <uikit/uikit.h># Import  <imageio/imageio.h> @interface      gifview:uiview{cgimagesourceref gif;    Nsdictionary  *gifproperties;    size_t index;    size_t count; Nstimer  *timer;}  -(id ) initWithFrame: (CGRect) frame FilePath: (NSString *  -(id ) initWithFrame: (CGRect) frame data: (NSData *   @end  
////gifview.m//Gifdemo//#import "GifView.h"#import<QuartzCore/QuartzCore.h>@implementationGifview- (ID) initWithFrame: (CGRect) frame FilePath: (NSString *) _filepath{ Self=[Super Initwithframe:frame]; if(self) {gifproperties= [Nsdictionary dictionarywithobject:[nsdictionary dictionarywithobject:[nsnumber numberWithInt:0] Forkey: (NSString *) Kcgimagepropertygifloopcount]forkey: (NSString *) kcgimagepropertygifdictionary]; GIF=Cgimagesourcecreatewithurl (__bridge cfurlref) [Nsurl Fileurlwithpath:_filepath], (__bridge CFDictionaryRef)        Gifproperties); Count=cgimagesourcegetcount (GIF); Timer= [Nstimer scheduledtimerwithtimeinterval:0.12target:self selector: @selector (play) Userinfo:nil Repeats:yes];    [Timer fire]; }    returnSelf ;}- (ID) initWithFrame: (CGRect) frame data: (NSData *) _data{ Self=[Super Initwithframe:frame]; if(self) {gifproperties= [Nsdictionary dictionarywithobject:[nsdictionary dictionarywithobject:[nsnumber numberWithInt:0] Forkey: (NSString *) Kcgimagepropertygifloopcount]forkey: (NSString *) kcgimagepropertygifdictionary]; GIF=Cgimagesourcecreatewithdata ((__bridge cfdataref) _data, (__bridge cfdictionaryref) gifproperties); Count=cgimagesourcegetcount (GIF); Timer= [Nstimer scheduledtimerwithtimeinterval:0.12target:self selector: @selector (play) Userinfo:nil Repeats:yes];    [Timer fire]; }    returnSelf ;}-(void) play{Index++; Index= index%count; Cgimagerefref=cgimagesourcecreateimageatindex (GIF, index, (__bridge cfdictionaryref) gifproperties); Self.layer.contents= (__bridgeID)ref; Cfrelease (ref);}-(void) removefromsuperview{NSLog (@"Removefromsuperview");    [Timer invalidate]; Timer=Nil; [Super Removefromsuperview];}- (void) dealloc{NSLog (@"Dealloc"); Cfrelease (GIF);}/*//Only override Drawrect:if your perform custom drawing.//An empty implementation adversely affects performance du Ring animation. -(void) DrawRect: (cgrect) Rect {//Drawing code}*/@end
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.