ios 价值GIF动画

来源:互联网 发布:好吃的零食推荐知乎 编辑:程序博客网 时间:2024/06/06 17:49
    加载GIF动画


    NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading_new.gif" withExtension:nil];


    if(url != nil){


        CGImageSourceRef csf = CGImageSourceCreateWithURL((__bridge CFTypeRef) url, NULL);


        size_t const count = CGImageSourceGetCount(csf);


        UIImage *frames[count];


        CGImageRef images[count];


        for (size_t i = 0; i < count; ++i) {


            images[i] = CGImageSourceCreateImageAtIndex(csf, i, NULL);


            UIImage *image =[[UIImage alloc] initWithCGImage:images[i]];


            frames[i] = image;


            CFRelease(images[i]);


        }


        


        m_animationPic = [UIImage animatedImageWithImages:[NSArray arrayWithObjects:frames count:count] duration:1.5];


        [self.gifView setImage:m_animationPic];


        


        CFRelease(csf);


    }
0 0
原创粉丝点击