Commit 9a2dc311da7ab4963e82f0b0e66bef6359a405d4

Authored by zhangxiaowen
1 parent 9c9b204a

no message

CNLivePreloadResources/Classes/CNLivePreloadManager.h
@@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
25 * 预加载 25 * 预加载
26 */ 26 */
27 + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type; 27 + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type;
  28 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForType:(CNLivePreloadType)type;
28 + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type; 29 + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type;
29 30
30 31
@@ -32,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -32,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
32 * 预加载刷新图片 33 * 预加载刷新图片
33 */ 34 */
34 + (CNLivePreloadModel *)preloadModelForRefreshImage; 35 + (CNLivePreloadModel *)preloadModelForRefreshImage;
  36 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForRefreshImage;
35 + (NSArray<UIImage *> *)preloadImagesForRefreshImage; 37 + (NSArray<UIImage *> *)preloadImagesForRefreshImage;
36 38
37 39
@@ -39,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -39,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
39 * 预加载Gif表情封面 41 * 预加载Gif表情封面
40 */ 42 */
41 + (CNLivePreloadModel *)preloadModelForGifCover; 43 + (CNLivePreloadModel *)preloadModelForGifCover;
  44 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForGifCover;
42 + (NSArray<UIImage *> *)preloadImagesForGifCover; 45 + (NSArray<UIImage *> *)preloadImagesForGifCover;
43 46
44 47
@@ -46,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -46,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
46 * 预加载Emotion表情 49 * 预加载Emotion表情
47 */ 50 */
48 + (CNLivePreloadModel *)preloadModelForEmotion; 51 + (CNLivePreloadModel *)preloadModelForEmotion;
  52 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForEmotion;
49 + (NSArray<UIImage *> *)preloadImagesForEmotion; 53 + (NSArray<UIImage *> *)preloadImagesForEmotion;
50 54
51 55
CNLivePreloadResources/Classes/CNLivePreloadManager.m
@@ -36,19 +36,19 @@ static NSMutableDictionary *resources; @@ -36,19 +36,19 @@ static NSMutableDictionary *resources;
36 */ 36 */
37 + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type{ 37 + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type{
38 switch (type) { 38 switch (type) {
39 - case CNLivePreloadRefreshImage://刷新图片 39 + case CNLivePreloadRefreshImage:// 刷新图片
40 { 40 {
41 [self preloadModelForRefreshImage]; 41 [self preloadModelForRefreshImage];
42 } 42 }
43 break; 43 break;
44 44
45 - case CNLivePreloadGifCover://Gif封面图片 45 + case CNLivePreloadGifCover:// Gif封面图片
46 { 46 {
47 [self preloadModelForGifCover]; 47 [self preloadModelForGifCover];
48 } 48 }
49 break; 49 break;
50 50
51 - case CNLivePreloadEmotion://Emotion表情 51 + case CNLivePreloadEmotion:// Emotion表情
52 { 52 {
53 [self preloadModelForEmotion]; 53 [self preloadModelForEmotion];
54 } 54 }
@@ -58,21 +58,45 @@ static NSMutableDictionary *resources; @@ -58,21 +58,45 @@ static NSMutableDictionary *resources;
58 return nil; 58 return nil;
59 59
60 } 60 }
  61 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForType:(CNLivePreloadType)type{
  62 + switch (type) {
  63 + case CNLivePreloadRefreshImage:// 刷新图片
  64 + {
  65 + [self preloadModelsForRefreshImage];
  66 + }
  67 + break;
  68 +
  69 + case CNLivePreloadGifCover:// Gif封面图片
  70 + {
  71 + [self preloadModelsForGifCover];
  72 + }
  73 + break;
  74 +
  75 + case CNLivePreloadEmotion:// Emotion表情
  76 + {
  77 + [self preloadModelsForEmotion];
  78 + }
  79 + break;
  80 +
  81 + }
  82 + return nil;
  83 +
  84 +}
61 + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type{ 85 + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type{
62 switch (type) { 86 switch (type) {
63 - case CNLivePreloadRefreshImage://刷新图片 87 + case CNLivePreloadRefreshImage:// 刷新图片
64 { 88 {
65 [self preloadImagesForRefreshImage]; 89 [self preloadImagesForRefreshImage];
66 } 90 }
67 break; 91 break;
68 92
69 - case CNLivePreloadGifCover://Gif封面图片 93 + case CNLivePreloadGifCover:// Gif封面图片
70 { 94 {
71 [self preloadImagesForGifCover]; 95 [self preloadImagesForGifCover];
72 } 96 }
73 break; 97 break;
74 98
75 - case CNLivePreloadEmotion://Emotion表情 99 + case CNLivePreloadEmotion:// Emotion表情
76 { 100 {
77 [self preloadImagesForEmotion]; 101 [self preloadImagesForEmotion];
78 } 102 }
@@ -97,6 +121,11 @@ static NSMutableDictionary *resources; @@ -97,6 +121,11 @@ static NSMutableDictionary *resources;
97 return model; 121 return model;
98 122
99 } 123 }
  124 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForRefreshImage{
  125 + CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage];
  126 + return model.models;
  127 +
  128 +}
100 + (NSArray<UIImage *> *)preloadImagesForRefreshImage{ 129 + (NSArray<UIImage *> *)preloadImagesForRefreshImage{
101 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage]; 130 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage];
102 return model.images; 131 return model.images;
@@ -117,6 +146,11 @@ static NSMutableDictionary *resources; @@ -117,6 +146,11 @@ static NSMutableDictionary *resources;
117 return model; 146 return model;
118 147
119 } 148 }
  149 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForGifCover{
  150 + CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover];
  151 + return model.models;
  152 +
  153 +}
120 + (NSArray<UIImage *> *)preloadImagesForGifCover{ 154 + (NSArray<UIImage *> *)preloadImagesForGifCover{
121 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover]; 155 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover];
122 return model.images; 156 return model.images;
@@ -139,6 +173,11 @@ static NSMutableDictionary *resources; @@ -139,6 +173,11 @@ static NSMutableDictionary *resources;
139 return model; 173 return model;
140 174
141 } 175 }
  176 ++ (NSArray<CNLiveResourceModel *> *)preloadModelsForEmotion{
  177 + CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion];
  178 + return model.models;
  179 +
  180 +}
142 + (NSArray<UIImage *> *)preloadImagesForEmotion{ 181 + (NSArray<UIImage *> *)preloadImagesForEmotion{
143 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion]; 182 CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion];
144 return model.images; 183 return model.images;
@@ -146,6 +185,15 @@ static NSMutableDictionary *resources; @@ -146,6 +185,15 @@ static NSMutableDictionary *resources;
146 } 185 }
147 186
148 #pragma mark - 私有方法 187 #pragma mark - 私有方法
  188 +/**
  189 + * 预加载资源
  190 + *
  191 + * @param preloadId 加载标识
  192 + * @param type 资源类型
  193 + * @param imageNames 资源名字数组
  194 + *
  195 + * @return 模型
  196 + */
149 + (CNLivePreloadModel *)preloadModelForPreloadId:(NSString *)preloadId type:(CNLiveResourceType)type imageNames:(NSArray<NSString *> *)imageNames { 197 + (CNLivePreloadModel *)preloadModelForPreloadId:(NSString *)preloadId type:(CNLiveResourceType)type imageNames:(NSArray<NSString *> *)imageNames {
150 if (resources) {// resources存在 198 if (resources) {// resources存在
151 CNLivePreloadModel *model = resources[preloadId]; 199 CNLivePreloadModel *model = resources[preloadId];
Example/CNLivePreloadResources/CNLiveAppDelegate.m
@@ -14,9 +14,8 @@ @@ -14,9 +14,8 @@
14 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
15 { 15 {
16 // Override point for customization after application launch. 16 // Override point for customization after application launch.
17 - [CNLivePreloadManager preloadAllResources];  
18 -// NSArray *add = [CNLivePreloadManager preloadImagesForRefreshImage];  
19 - 17 +// [CNLivePreloadManager preloadAllResources];
  18 + [CNLivePreloadManager preloadModelForRefreshImage];
20 return YES; 19 return YES;
21 } 20 }
22 21
Example/CNLivePreloadResources/CNLiveViewController.m
@@ -20,13 +20,15 @@ @@ -20,13 +20,15 @@
20 [super viewDidLoad]; 20 [super viewDidLoad];
21 // Do any additional setup after loading the view, typically from a nib. 21 // Do any additional setup after loading the view, typically from a nib.
22 UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 30)]; 22 UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 30)];
  23 + image1.backgroundColor = [UIColor redColor];
23 [self.view addSubview:image1]; 24 [self.view addSubview:image1];
24 25
25 UIImageView *image2 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 30, 30)]; 26 UIImageView *image2 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 30, 30)];
  27 + image2.backgroundColor = [UIColor greenColor];
26 [self.view addSubview:image2]; 28 [self.view addSubview:image2];
27 29
28 30
29 - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 31 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
30 NSArray *add1 = [CNLivePreloadManager preloadImagesForRefreshImage]; 32 NSArray *add1 = [CNLivePreloadManager preloadImagesForRefreshImage];
31 // NSMutableArray *images = [[NSMutableArray alloc] init]; 33 // NSMutableArray *images = [[NSMutableArray alloc] init];
32 // for(CNLivePreloadModel *model in add){ 34 // for(CNLivePreloadModel *model in add){
@@ -38,8 +40,8 @@ @@ -38,8 +40,8 @@
38 image1.animationRepeatCount = 0;//设置动画次数 0 表示无限 40 image1.animationRepeatCount = 0;//设置动画次数 0 表示无限
39 [image1 startAnimating];//开始播放动 41 [image1 startAnimating];//开始播放动
40 42
41 - NSArray *add2 = [CNLivePreloadManager preloadImagesForEmotion];  
42 - image2.image = add2[2]; 43 +// NSArray *add2 = [CNLivePreloadManager preloadImagesForEmotion];
  44 +// image2.image = add2[2];
43 }); 45 });
44 } 46 }
45 47