Commit b14c0f688efc1096be92a58751819a3414bfb3b8
1 parent
9a2dc311
no message
Showing
6 changed files
with
15 additions
and
55 deletions
CNLivePreloadResources.podspec
| @@ -41,4 +41,5 @@ TODO: Add long description of the pod here. | @@ -41,4 +41,5 @@ TODO: Add long description of the pod here. | ||
| 41 | # s.public_header_files = 'Pod/Classes/**/*.h' | 41 | # s.public_header_files = 'Pod/Classes/**/*.h' |
| 42 | # s.frameworks = 'UIKit', 'MapKit' | 42 | # s.frameworks = 'UIKit', 'MapKit' |
| 43 | # s.dependency 'AFNetworking', '~> 2.3' | 43 | # s.dependency 'AFNetworking', '~> 2.3' |
| 44 | + | ||
| 44 | end | 45 | end |
CNLivePreloadResources/Classes/CNLivePreloadManager.h
| @@ -12,6 +12,16 @@ | @@ -12,6 +12,16 @@ | ||
| 12 | NS_ASSUME_NONNULL_BEGIN | 12 | NS_ASSUME_NONNULL_BEGIN |
| 13 | 13 | ||
| 14 | @interface CNLivePreloadManager : NSObject | 14 | @interface CNLivePreloadManager : NSObject |
| 15 | +/** | ||
| 16 | + * 预加载资源 | ||
| 17 | + * | ||
| 18 | + * @param preloadId 加载标识 | ||
| 19 | + * @param type 资源类型 | ||
| 20 | + * @param imageNames 资源名字数组 | ||
| 21 | + * | ||
| 22 | + * @return 模型 | ||
| 23 | + */ | ||
| 24 | ++ (CNLivePreloadModel *)preloadModelForPreloadId:(NSString *)preloadId type:(CNLiveResourceType)type imageNames:(NSArray<NSString *> *)imageNames; | ||
| 15 | 25 | ||
| 16 | #pragma mark - 针对具体业务 | 26 | #pragma mark - 针对具体业务 |
| 17 | /** | 27 | /** |
| @@ -25,7 +35,6 @@ NS_ASSUME_NONNULL_BEGIN | @@ -25,7 +35,6 @@ NS_ASSUME_NONNULL_BEGIN | ||
| 25 | * 预加载 | 35 | * 预加载 |
| 26 | */ | 36 | */ |
| 27 | + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type; | 37 | + (CNLivePreloadModel *)preloadModelForType:(CNLivePreloadType)type; |
| 28 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForType:(CNLivePreloadType)type; | ||
| 29 | + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type; | 38 | + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type; |
| 30 | 39 | ||
| 31 | 40 | ||
| @@ -33,7 +42,6 @@ NS_ASSUME_NONNULL_BEGIN | @@ -33,7 +42,6 @@ NS_ASSUME_NONNULL_BEGIN | ||
| 33 | * 预加载刷新图片 | 42 | * 预加载刷新图片 |
| 34 | */ | 43 | */ |
| 35 | + (CNLivePreloadModel *)preloadModelForRefreshImage; | 44 | + (CNLivePreloadModel *)preloadModelForRefreshImage; |
| 36 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForRefreshImage; | ||
| 37 | + (NSArray<UIImage *> *)preloadImagesForRefreshImage; | 45 | + (NSArray<UIImage *> *)preloadImagesForRefreshImage; |
| 38 | 46 | ||
| 39 | 47 | ||
| @@ -41,7 +49,6 @@ NS_ASSUME_NONNULL_BEGIN | @@ -41,7 +49,6 @@ NS_ASSUME_NONNULL_BEGIN | ||
| 41 | * 预加载Gif表情封面 | 49 | * 预加载Gif表情封面 |
| 42 | */ | 50 | */ |
| 43 | + (CNLivePreloadModel *)preloadModelForGifCover; | 51 | + (CNLivePreloadModel *)preloadModelForGifCover; |
| 44 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForGifCover; | ||
| 45 | + (NSArray<UIImage *> *)preloadImagesForGifCover; | 52 | + (NSArray<UIImage *> *)preloadImagesForGifCover; |
| 46 | 53 | ||
| 47 | 54 | ||
| @@ -49,7 +56,6 @@ NS_ASSUME_NONNULL_BEGIN | @@ -49,7 +56,6 @@ NS_ASSUME_NONNULL_BEGIN | ||
| 49 | * 预加载Emotion表情 | 56 | * 预加载Emotion表情 |
| 50 | */ | 57 | */ |
| 51 | + (CNLivePreloadModel *)preloadModelForEmotion; | 58 | + (CNLivePreloadModel *)preloadModelForEmotion; |
| 52 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForEmotion; | ||
| 53 | + (NSArray<UIImage *> *)preloadImagesForEmotion; | 59 | + (NSArray<UIImage *> *)preloadImagesForEmotion; |
| 54 | 60 | ||
| 55 | 61 |
CNLivePreloadResources/Classes/CNLivePreloadManager.m
| @@ -58,30 +58,6 @@ static NSMutableDictionary *resources; | @@ -58,30 +58,6 @@ 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 | -} | ||
| 85 | + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type{ | 61 | + (NSArray<UIImage *> *)preloadImagesForType:(CNLivePreloadType)type{ |
| 86 | switch (type) { | 62 | switch (type) { |
| 87 | case CNLivePreloadRefreshImage:// 刷新图片 | 63 | case CNLivePreloadRefreshImage:// 刷新图片 |
| @@ -121,11 +97,6 @@ static NSMutableDictionary *resources; | @@ -121,11 +97,6 @@ static NSMutableDictionary *resources; | ||
| 121 | return model; | 97 | return model; |
| 122 | 98 | ||
| 123 | } | 99 | } |
| 124 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForRefreshImage{ | ||
| 125 | - CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage]; | ||
| 126 | - return model.models; | ||
| 127 | - | ||
| 128 | -} | ||
| 129 | + (NSArray<UIImage *> *)preloadImagesForRefreshImage{ | 100 | + (NSArray<UIImage *> *)preloadImagesForRefreshImage{ |
| 130 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage]; | 101 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForRefreshImage]; |
| 131 | return model.images; | 102 | return model.images; |
| @@ -146,11 +117,6 @@ static NSMutableDictionary *resources; | @@ -146,11 +117,6 @@ static NSMutableDictionary *resources; | ||
| 146 | return model; | 117 | return model; |
| 147 | 118 | ||
| 148 | } | 119 | } |
| 149 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForGifCover{ | ||
| 150 | - CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover]; | ||
| 151 | - return model.models; | ||
| 152 | - | ||
| 153 | -} | ||
| 154 | + (NSArray<UIImage *> *)preloadImagesForGifCover{ | 120 | + (NSArray<UIImage *> *)preloadImagesForGifCover{ |
| 155 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover]; | 121 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForGifCover]; |
| 156 | return model.images; | 122 | return model.images; |
| @@ -173,18 +139,12 @@ static NSMutableDictionary *resources; | @@ -173,18 +139,12 @@ static NSMutableDictionary *resources; | ||
| 173 | return model; | 139 | return model; |
| 174 | 140 | ||
| 175 | } | 141 | } |
| 176 | -+ (NSArray<CNLiveResourceModel *> *)preloadModelsForEmotion{ | ||
| 177 | - CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion]; | ||
| 178 | - return model.models; | ||
| 179 | - | ||
| 180 | -} | ||
| 181 | + (NSArray<UIImage *> *)preloadImagesForEmotion{ | 142 | + (NSArray<UIImage *> *)preloadImagesForEmotion{ |
| 182 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion]; | 143 | CNLivePreloadModel *model = [CNLivePreloadManager preloadModelForEmotion]; |
| 183 | return model.images; | 144 | return model.images; |
| 184 | 145 | ||
| 185 | } | 146 | } |
| 186 | 147 | ||
| 187 | -#pragma mark - 私有方法 | ||
| 188 | /** | 148 | /** |
| 189 | * 预加载资源 | 149 | * 预加载资源 |
| 190 | * | 150 | * |
| @@ -235,6 +195,7 @@ static NSMutableDictionary *resources; | @@ -235,6 +195,7 @@ static NSMutableDictionary *resources; | ||
| 235 | return model; | 195 | return model; |
| 236 | } | 196 | } |
| 237 | 197 | ||
| 198 | +#pragma mark - 私有方法 | ||
| 238 | /** | 199 | /** |
| 239 | * 在子线程预加载 | 200 | * 在子线程预加载 |
| 240 | * | 201 | * |
CNLivePreloadResources/Classes/CNLivePreloadModel.m
Example/CNLivePreloadResources/CNLiveAppDelegate.m
| @@ -14,8 +14,7 @@ | @@ -14,8 +14,7 @@ | ||
| 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 | - [CNLivePreloadManager preloadModelForRefreshImage]; | 17 | + [CNLivePreloadManager preloadAllResources]; |
| 19 | return YES; | 18 | return YES; |
| 20 | } | 19 | } |
| 21 | 20 |
Example/CNLivePreloadResources/CNLiveViewController.m
| @@ -30,18 +30,13 @@ | @@ -30,18 +30,13 @@ | ||
| 30 | 30 | ||
| 31 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6.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(), ^{ |
| 32 | NSArray *add1 = [CNLivePreloadManager preloadImagesForRefreshImage]; | 32 | NSArray *add1 = [CNLivePreloadManager preloadImagesForRefreshImage]; |
| 33 | -// NSMutableArray *images = [[NSMutableArray alloc] init]; | ||
| 34 | -// for(CNLivePreloadModel *model in add){ | ||
| 35 | -// [images addObject:model.image]; | ||
| 36 | -// } | ||
| 37 | -// | ||
| 38 | image1.animationImages = add1;//将序列帧数组赋给UIImageView的animationImages属性 | 33 | image1.animationImages = add1;//将序列帧数组赋给UIImageView的animationImages属性 |
| 39 | image1.animationDuration = 1.0;//设置动画时间 | 34 | image1.animationDuration = 1.0;//设置动画时间 |
| 40 | image1.animationRepeatCount = 0;//设置动画次数 0 表示无限 | 35 | image1.animationRepeatCount = 0;//设置动画次数 0 表示无限 |
| 41 | [image1 startAnimating];//开始播放动 | 36 | [image1 startAnimating];//开始播放动 |
| 42 | 37 | ||
| 43 | -// NSArray *add2 = [CNLivePreloadManager preloadImagesForEmotion]; | ||
| 44 | -// image2.image = add2[2]; | 38 | + NSArray *add2 = [CNLivePreloadManager preloadImagesForEmotion]; |
| 39 | + image2.image = add2[2]; | ||
| 45 | }); | 40 | }); |
| 46 | } | 41 | } |
| 47 | 42 |