青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

路漫漫,長(zhǎng)修遠(yuǎn),我們不能沒有錢
隨筆 - 173, 文章 - 0, 評(píng)論 - 257, 引用 - 0
數(shù)據(jù)加載中……

IOS GIF播放, 包含UITableViewCell中正常播放


本程序依賴第三方庫(kù)UIImage+animatedImageWithGIF, 但是有小幅度修改
 1 //
 2 //  UIImage+animatedImageWithGIF.h
 3 //
 4 //  Created by YuAo on 2/24/12.
 5 //  Copyright (c) 2012 eico design. All rights reserved.
 6 //
 7 //  Note: 
 8 //        ImageIO.framework is needed.
 9 //        This lib is only available on iOS 4+
10 
11 #import <Foundation/Foundation.h>
12 
13 @interface UIImageView(animatedImageViewWithGIF)
14 + (UIImageView *)imageViewWithGIFData:(NSData *)data;
15 //+ (UIImageView *)imageViewWithGIFURL:(NSURL *)url;
16 @end
 


 1 //
 2 //  UIImage+animatedImageWithGIF.m
 3 //
 4 //  Created by YuAo on 2/24/12.
 5 //  Copyright (c) 2012 eico design. All rights reserved.
 6 //
 7 
 8 #import "UIImageView+imageViewWithGIF.h"
 9 #import <ImageIO/ImageIO.h>
10 
11 #if __has_feature(objc_arc)
12     #define toCF (__bridge CFTypeRef)
13     #define ARCCompatibleAutorelease(object) object
14 #else
15     #define toCF (CFTypeRef)
16     #define ARCCompatibleAutorelease(object) [object autorelease]
17 #endif
18 
19 @implementation UIImageView(animatedImageViewWithGIF)
20 
21 + (UIImageView *)imageViewWithAnimatedGIFImageSource:(CGImageSourceRef) source 
22                                          andDuration:(NSTimeInterval) duration {
23     if (!source) return nil;
24     size_t count = CGImageSourceGetCount(source);
25     NSMutableArray *images = [NSMutableArray arrayWithCapacity:count];
26 
27     for (size_t i = 0; i < count; ++i) {
28         CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, i, NULL);
29         if (!cgImage)
30             return nil;
31         [images addObject:[UIImage imageWithCGImage:cgImage]];
32         CGImageRelease(cgImage);
33     }
34     UIImageView *imageView = [[UIImageView alloc] init];
35     if ([images count] > 0) {
36         imageView.image = [images objectAtIndex:0];
37     }
38     [imageView setAnimationImages:images];
39     [imageView setHighlighted:NO];
40 //    [imageView setHighlightedAnimationImages:images];
41     [imageView setAnimationDuration:duration];
42     [imageView sizeToFit];
43     NSArray *arr = [NSArray arrayWithObject:NSRunLoopCommonModes]; //優(yōu)先級(jí)提升. 可以解決tableview滾動(dòng)時(shí)動(dòng)畫暫停的問題
44     [imageView performSelector:@selector(startAnimating) withObject:nil afterDelay:0.1f inModes:arr];
45 //    NSLog(@"begin");
46     return ARCCompatibleAutorelease(imageView);
47 }
48 
49 + (NSTimeInterval)durationForGifData:(NSData *)data {
50     char graphicControlExtensionStartBytes[] = {0x21,0xF9,0x04};
51     double duration=0;
52     NSRange dataSearchLeftRange = NSMakeRange(0, data.length);
53     while(YES){
54         NSRange frameDescriptorRange = [data rangeOfData:[NSData dataWithBytes:graphicControlExtensionStartBytes 
55                                                                         length:3] 
56                                                  options:NSDataSearchBackwards
57                                                    range:dataSearchLeftRange];
58         if(frameDescriptorRange.location != NSNotFound){
59             NSData *durationData = [data subdataWithRange:NSMakeRange(frameDescriptorRange.location+4, 2)];
60             unsigned char buffer[2];
61             [durationData getBytes:buffer];
62             double delay = (buffer[0] | buffer[1] << 8);
63             duration += delay;
64             dataSearchLeftRange = NSMakeRange(0, frameDescriptorRange.location);
65         }else{
66             break;
67         }
68     }
69     return duration/100;
70 }
71 
72 + (UIImageView *)imageViewWithGIFData:(NSData *)data{
73     NSTimeInterval duration = [self durationForGifData:data];
74     CGImageSourceRef source = CGImageSourceCreateWithData(toCF data, NULL);
75     UIImageView *imageView = [UIImageView imageViewWithAnimatedGIFImageSource:source andDuration:duration]; 
76     CFRelease(source);
77     return imageView;
78 }
79 
80 //+ (UIImageView *)imageViewWithGIFURL:(NSURL *)url{
81 //    NSData *data = [NSData dataWithContentsOfURL:url];
82 //    return [UIImageView imageViewWithGIFData:data];
83 //}
84 
85 @end
86 

 1 //
 2 //  testViewController.h
 3 //  UIImageViewGIF
 4 //
 5 //  Created by khan.lau on 13-2-26.
 6 //
 7 //
 8 
 9 #import <UIKit/UIKit.h>
10 
11 @interface testViewController : UITableViewController
12 
13 @end


  1 //  在UITableview中顯示的范例
  2 //  testViewController.m
  3 //  UIImageViewGIF
  4 //
  5 //  Created by khan.lau on 13-2-26.
  6 //
  7 //
  8 
  9 #import "testViewController.h"
 10 #import "UIImageView+imageViewWithGIF.h"
 11 
 12 @interface testViewController ()
 13 
 14 @end
 15 
 16 @implementation testViewController
 17 
 18 - (id)initWithStyle:(UITableViewStyle)style
 19 {
 20     self = [super initWithStyle:style];
 21     if (self) {
 22         // Custom initialization
 23     }
 24     return self;
 25 }
 26 
 27 - (void)viewDidLoad
 28 {
 29     [super viewDidLoad];
 30     UIBarButtonItem *exitBtn = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(doExit:)]  ;
 31     self.navigationItem.leftBarButtonItem = exitBtn;
 32     // Uncomment the following line to preserve selection between presentations.
 33     // self.clearsSelectionOnViewWillAppear = NO;
 34  
 35     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
 36     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
 37     
 38 }
 39 - (void)reStartAnimating{
 40     NSArray *vc = [self.tableView visibleCells];
 41     for (UITableViewCell *cell in vc) {
 42 //        NSLog(@"%d", [cell isSelected]);
 43 //        if ([cell isSelected] == NO) {
 44 //            continue;
 45 //        }
 46         for (UIView *v in [cell.contentView subviews]) {
 47             if ([v isKindOfClass:[UIImageView class]]){
 48                 UIImageView * imageview = (UIImageView *)v;
 49                 if ([imageview isAnimating] == NO) {
 50                     [imageview startAnimating];
 51                 }
 52             }
 53         }
 54     }
 55 }
 56 
 57 - (void)didReceiveMemoryWarning
 58 {
 59     [super didReceiveMemoryWarning];
 60     // Dispose of any resources that can be recreated.
 61 }
 62 -(void)doExit:(id)sender{
 63     [self.parentViewController dismissViewControllerAnimated:YES completion:^{}];
 64     //    [self.parentViewController dismissModalViewControllerAnimated:YES];
 65 }
 66 #pragma mark - Table view data source
 67 
 68 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 69 {
 70     // Return the number of sections.
 71     return 1;
 72 }
 73 
 74 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 75 {
 76     // Return the number of rows in the section.
 77     return 8;
 78 }
 79 
 80 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 81 {
 82     static NSString *CellIdentifier = @"Cell";
 83     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 84     if (cell == nil) {
 85         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
 86     }
 87 
 88     for (UIView *v in [cell.contentView subviews]) {
 89         if ([v isKindOfClass:[UIView class]]){
 90             [v removeFromSuperview];
 91         }
 92     }
 93     if ([indexPath row] == 0) {
 94 //        NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
 95 //                                                          pathForResource:@"demo"
 96 //                                                          ofType:@"gif"]];
 97         UIImageView *imageView = [[UIImageView alloc] init];
 98         imageView.image = [UIImage imageNamed:@"IMG_0015.jpg"];
 99         imageView.frame = CGRectMake(0, 0, 100, 100);
100         [cell.contentView addSubview:imageView];
101     }else if ( [indexPath row] == 1){
102         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
103                                                           pathForResource:@"bbb"
104                                                           ofType:@"gif"]];
105         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
106         imageView.frame = CGRectMake(0, 0, 100, 100);
107         [cell.contentView addSubview:imageView];
108     }else if ( [indexPath row] == 2){
109         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
110                                                           pathForResource:@"demo"
111                                                           ofType:@"gif"]];
112         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
113         imageView.frame = CGRectMake(0, 0, 100, 100);
114         [cell.contentView addSubview:imageView];
115     }else if ( [indexPath row] == 3){
116         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
117                                                           pathForResource:@"bbb"
118                                                           ofType:@"gif"]];
119         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
120         imageView.frame = CGRectMake(0, 0, 100, 100);
121         [cell.contentView addSubview:imageView];
122     }else if ( [indexPath row] == 4){
123         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
124                                                           pathForResource:@"demo"
125                                                           ofType:@"gif"]];
126         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
127         imageView.frame = CGRectMake(0, 0, 100, 100);
128         [cell.contentView addSubview:imageView];
129     }else if ( [indexPath row] == 5){
130         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
131                                                           pathForResource:@"bbb"
132                                                           ofType:@"gif"]];
133         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
134         imageView.frame = CGRectMake(0, 0, 100, 100);
135         [cell.contentView addSubview:imageView];
136     }else if ( [indexPath row] == 6){
137         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
138                                                           pathForResource:@"demo"
139                                                           ofType:@"gif"]];
140         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
141         imageView.frame = CGRectMake(0, 0, 100, 100);
142         [cell.contentView addSubview:imageView];
143     }else if ( [indexPath row] == 7){
144         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
145                                                           pathForResource:@"bbb"
146                                                           ofType:@"gif"]];
147         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
148         imageView.frame = CGRectMake(0, 0, 100, 100);
149         [cell.contentView addSubview:imageView];
150     }else{
151         NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
152                                                           pathForResource:@"bbb"
153                                                           ofType:@"gif"]];
154         UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
155         imageView.frame = CGRectMake(0, 0, 100, 100);
156         [cell.contentView addSubview:imageView];
157     }
158     
159 
160 //    [self performSelector:@selector(reStartAnimating) withObject:nil afterDelay:0.3f];
161     return cell;
162 }
163 //行高度
164 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
165     if ([indexPath section]==0) {
166         return 115;
167     } else
168         return 50;
169 }
170 
171 //判斷選中的行
172 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
173 //    [self reStartAnimating];
174     return indexPath;
175 }
176 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
177     [self performSelector:@selector(reStartAnimating) withObject:nil afterDelay:0.3f];
178 //    [tableView deselectRowAtIndexPath:indexPath animated:YES];//選中后的反顯顏色即刻消失
179 }
180 
181 
182 - (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
183 //    [self reStartAnimating];
184     return indexPath;
185 }
186 // Called after the user changes the selection.
187 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
188     [self performSelector:@selector(reStartAnimating) withObject:nil afterDelay:0.3f];
189 }
190 
191 
192 
193 @end
194 

 1 //  主界面入口.... 包含在正常的UIViewController中顯示gif
 2 //  DemoViewController.m
 3 //  UIImageViewGIF
 4 //
 5 //  Created by YuAo on 2/27/12.
 6 //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
 7 //
 8 
 9 #import "DemoViewController.h"
10 #import "UIImageView+imageViewWithGIF.h"
11 #import "testViewController.h"
12 
13 @implementation DemoViewController
14 
15 - (void)loadView {
16     UIView *mainView = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];
17     mainView.backgroundColor = [UIColor whiteColor];
18     
19     NSData *gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] 
20                                      pathForResource:@"demo"
21                                               ofType:@"gif"]];
22     UIImageView *imageView = [UIImageView imageViewWithGIFData:gifData];
23     imageView.frame = CGRectMake(90, 100, 100, 100);
24     [mainView addSubview:imageView];
25     
26     NSData *gifData1 = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]
27                                                       pathForResource:@"bbb"
28                                                       ofType:@"gif"]];
29     UIImageView *imageView1 = [UIImageView imageViewWithGIFData:gifData1];
30     imageView1.frame = CGRectMake(90, 0, 100, 100);
31     [mainView addSubview:imageView1];
32     self.view = mainView;
33     
34     UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
35     button.frame = CGRectMake(10, 10, 70, 40);
36     [button setTitle:@"表格測(cè)試" forState:UIControlStateNormal];
37     [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
38     [mainView addSubview:button];
39 }
40 
41 -(IBAction) click:(UIButton*) sender{
42     testViewController * detail = [[testViewController alloc] init];
43     detail.hidesBottomBarWhenPushed = YES;
44     
45     detail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
46     UINavigationController *vd = [[UINavigationController alloc] initWithRootViewController:detail];
47     [vd.navigationBar.topItem setTitle: @"用戶注冊(cè)"];
48     [self presentViewController:vd animated:YES completion:^{}];
49 }
50 @end

重點(diǎn)需要注意TableViewCell選中狀態(tài)會(huì)對(duì)動(dòng)畫播放造成影響, 因此我將動(dòng)畫播放延時(shí)0.3s執(zhí)行 避開事件沖突



posted on 2013-02-27 02:40 Khan 閱讀(2746) 評(píng)論(0)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺(tái)開發(fā)

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品一区二区三区福利| 亚洲免费视频一区二区| 亚洲国内精品在线| 激情综合激情| 这里只有精品在线播放| 伊人久久男人天堂| 你懂的成人av| 欧美日韩一区三区四区| 久久综合99re88久久爱| 欧美在线视频观看免费网站| 久久精品视频在线| 欧美在线影院| 欧美与黑人午夜性猛交久久久| 欧美在线地址| 久久九九免费视频| 久久久久久久久伊人| 亚洲福利在线看| 日韩一级不卡| 亚洲一级片在线观看| 国内外成人免费激情在线视频 | 在线精品亚洲| 在线观看日韩一区| 在线国产亚洲欧美| 亚洲一区精彩视频| 午夜天堂精品久久久久| 香蕉免费一区二区三区在线观看| 欧美一区二区日韩一区二区| 欧美一区二区在线播放| 久久伊人免费视频| 日韩午夜在线视频| 亚洲永久免费精品| 欧美中文在线视频| 欧美日本亚洲韩国国产| 欧美视频一二三区| 国产午夜精品视频| 一本色道久久综合狠狠躁篇怎么玩 | 老牛国产精品一区的观看方式| 美女福利精品视频| 国产精品视频午夜| 一区二区视频免费在线观看| 最新中文字幕一区二区三区| 欧美一区二区视频免费观看| 欧美成人国产| 亚洲最新视频在线| 欧美国产精品专区| 国产欧美日韩一区二区三区在线| 伊人色综合久久天天五月婷| 性高湖久久久久久久久| 亚洲福利专区| 亚洲一区免费在线观看| 欧美国产高清| 激情综合色综合久久| 一区二区三区福利| 欧美国产一区视频在线观看 | 国产乱码精品一区二区三| 欧美一区二区三区啪啪| 美女精品自拍一二三四| 欧美凹凸一区二区三区视频| 欧美在线视频一区| 亚洲黄色片网站| 国产精品99久久久久久久久久久久 | 女生裸体视频一区二区三区| 韩国欧美国产1区| 美日韩精品免费| 99精品国产高清一区二区| 国产香蕉久久精品综合网| 久久国产精品久久w女人spa| 午夜精品www| 中文在线不卡视频| 亚洲欧美一区二区在线观看| 在线播放亚洲一区| 午夜精品久久久久久久男人的天堂 | 久久国产成人| 男女视频一区二区| 亚洲天堂第二页| 午夜激情久久久| 亚洲欧洲一区二区天堂久久| 夜夜夜久久久| 亚洲高清视频中文字幕| 宅男噜噜噜66一区二区| 国产一区二区毛片| 亚洲欧洲视频在线| 欧美日本一区二区三区| 老司机午夜免费精品视频 | 欧美精品一区在线| 久久精品视频一| 国产精品久久久久久妇女6080| 麻豆av一区二区三区| 欧美日韩国产在线播放网站| 亚洲成色最大综合在线| 国产日本欧美一区二区三区在线| 亚洲国产精品成人精品| 亚洲三级免费| 久久久久久久久蜜桃| 亚洲欧美在线另类| 国产精品任我爽爆在线播放 | 9l视频自拍蝌蚪9l视频成人| 免费国产一区二区| 久久久久网址| 国产精品wwwwww| 正在播放欧美视频| 国产精品一区视频网站| 国内揄拍国内精品久久| 亚洲另类一区二区| 亚洲国产精品久久人人爱蜜臀| 亚洲午夜免费视频| 亚洲国产成人精品女人久久久| 亚洲综合成人婷婷小说| 亚洲网站在线观看| 久久久久久电影| 在线视频日韩精品| 欧美激情性爽国产精品17p| 玖玖国产精品视频| 最近看过的日韩成人| 久久精品一区| 久久天天躁夜夜躁狠狠躁2022| 国产综合色一区二区三区 | 欧美日韩久久精品| 99国产精品视频免费观看| 亚洲精品视频在线播放| 免费人成精品欧美精品| 亚洲精品影院在线观看| 一区二区免费看| 欧美日韩免费一区二区三区| 亚洲午夜电影| 欧美一区1区三区3区公司| 国产精品久久777777毛茸茸| 亚洲欧美在线视频观看| 欧美一区二区三区在线观看| 国产精品久久久一本精品| 欧美一站二站| 蜜桃伊人久久| 亚洲激情黄色| 国产精品免费看久久久香蕉| 亚洲一级高清| 久久久五月婷婷| 91久久在线播放| 欧美肉体xxxx裸体137大胆| 亚洲一区激情| 亚洲女人天堂成人av在线| 国产色视频一区| 久久网站免费| 夜夜嗨av一区二区三区| 久久人人爽国产| 亚洲精品久久久久久久久久久久久 | 亚洲午夜91| 国语自产精品视频在线看抢先版结局| 美国成人毛片| 亚洲深夜福利视频| 久久久蜜桃一区二区人| 中文精品视频一区二区在线观看| 国产精品热久久久久夜色精品三区| 欧美一区二区三区视频在线观看| 亚洲激情六月丁香| 欧美影院在线| 亚洲国产精品一区二区三区| 国产精品久久久久999| 欧美中文字幕视频在线观看| 亚洲第一二三四五区| 久久精品国产99国产精品| 亚洲精品色婷婷福利天堂| 国产精品成人免费| 欧美激情一区二区三级高清视频 | 国产精品网站一区| 欧美成人一区二区三区片免费| 国产美女诱惑一区二区| 亚洲一区二区三区四区中文| 欧美高清视频免费观看| 欧美一区亚洲| 国产三级精品三级| 亚洲欧洲日夜超级视频| 国产精品视频一二三| 亚洲国产欧美日韩另类综合| 亚洲一区二区三区在线看| 亚洲人成网站影音先锋播放| 在线看欧美视频| 国产一区二区三区四区五区美女 | 狠狠色伊人亚洲综合成人| 国产精品亚洲综合久久| 国产精品激情偷乱一区二区∴| 欧美日韩国产一区二区三区地区 | 欧美亚男人的天堂| 欧美色图一区二区三区| 欧美日韩一区二区视频在线观看| 欧美另类极品videosbest最新版本| 麻豆成人在线观看| 欧美成人一品| 欧美日韩一区二区三区四区在线观看| 欧美日韩一区免费| 国产欧美精品国产国产专区| 国产日韩欧美综合一区| 激情久久综艺| 亚洲三级电影全部在线观看高清 | 在线视频一区二区| 性久久久久久| 老牛国产精品一区的观看方式| 男人的天堂亚洲| 欧美午夜精品久久久久久超碰| 国产精品成人一区二区网站软件| 国产精品美女久久久免费|