From 81167d8e0f9a46ac7c27f5046a36298096bfe9a2 Mon Sep 17 00:00:00 2001 From: eggmanQQQ <3671373519@qq.com> Date: Fri, 18 Oct 2024 20:24:47 +0800 Subject: [PATCH] temp save --- YuMi.xcodeproj/project.pbxproj | 6 + YuMi/Global/YUMIMacroUitls.h | 6 +- .../Presenter/XPMineUserInfoEditPresenter.h | 1 + .../Presenter/XPMineUserInfoEditPresenter.m | 14 + .../XPMineUserInfoEditViewController.m | 101 ++++++- .../LuckyGiftWinningBannerView.m | 1 + YuMi/Modules/YMWeb/XPWebViewController.m | 3 +- .../File/AlbumResourcePickerViewController.h | 19 ++ .../File/AlbumResourcePickerViewController.m | 281 ++++++++++++++++++ 9 files changed, 417 insertions(+), 15 deletions(-) create mode 100644 YuMi/Tools/File/AlbumResourcePickerViewController.h create mode 100644 YuMi/Tools/File/AlbumResourcePickerViewController.m diff --git a/YuMi.xcodeproj/project.pbxproj b/YuMi.xcodeproj/project.pbxproj index 2659c985..37ed766e 100644 --- a/YuMi.xcodeproj/project.pbxproj +++ b/YuMi.xcodeproj/project.pbxproj @@ -522,6 +522,7 @@ 547853A12C258F2A00F45E60 /* XPMineUserViewHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 547853A02C258F2A00F45E60 /* XPMineUserViewHeader.m */; }; 547B30F92CB511700041E962 /* RoomBoomEntryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 547B30F82CB511700041E962 /* RoomBoomEntryView.m */; }; 5484E1FD2CA2897B008E8754 /* IAPManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5484E1FC2CA2897B008E8754 /* IAPManager.m */; }; + 548D54202CC208FD0084A2FF /* AlbumResourcePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 548D541F2CC208FD0084A2FF /* AlbumResourcePickerViewController.m */; }; 548E01C52C3F78360071C83D /* FeedBackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 548E01C22C3F78360071C83D /* FeedBackViewController.xib */; }; 548E01C62C3F78360071C83D /* FeedBackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 548E01C42C3F78360071C83D /* FeedBackViewController.m */; }; 548E01C92C3F78600071C83D /* FeedBackConfigModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 548E01C82C3F78600071C83D /* FeedBackConfigModel.m */; }; @@ -2608,6 +2609,8 @@ 547B30F82CB511700041E962 /* RoomBoomEntryView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RoomBoomEntryView.m; sourceTree = ""; }; 5484E1FB2CA2897B008E8754 /* IAPManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IAPManager.h; sourceTree = ""; }; 5484E1FC2CA2897B008E8754 /* IAPManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IAPManager.m; sourceTree = ""; }; + 548D541E2CC208FD0084A2FF /* AlbumResourcePickerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlbumResourcePickerViewController.h; sourceTree = ""; }; + 548D541F2CC208FD0084A2FF /* AlbumResourcePickerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AlbumResourcePickerViewController.m; sourceTree = ""; }; 548E01C22C3F78360071C83D /* FeedBackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FeedBackViewController.xib; sourceTree = ""; }; 548E01C32C3F78360071C83D /* FeedBackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FeedBackViewController.h; sourceTree = ""; }; 548E01C42C3F78360071C83D /* FeedBackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FeedBackViewController.m; sourceTree = ""; }; @@ -6749,6 +6752,8 @@ 9B33E3C927D85379003B0E62 /* UploadFile.m */, 23959FE52BB15C930085A282 /* UploadFileModel.h */, 23959FE62BB15C930085A282 /* UploadFileModel.m */, + 548D541E2CC208FD0084A2FF /* AlbumResourcePickerViewController.h */, + 548D541F2CC208FD0084A2FF /* AlbumResourcePickerViewController.m */, ); path = File; sourceTree = ""; @@ -11915,6 +11920,7 @@ E85E7B022A4EB0D200B6D00A /* XPSuperAdminManagerRoomPresenter.m in Sources */, 237700DD2BC7D70E00D661F1 /* UIImage+MSRTL.m in Sources */, E8AB633328AE51470023B0D2 /* XPSailingPrizeView.m in Sources */, + 548D54202CC208FD0084A2FF /* AlbumResourcePickerViewController.m in Sources */, 9B2F72D328E45C5A0000E4FA /* XPRoomQuidkMessageCell.m in Sources */, E85E7B402A4EB0D300B6D00A /* XPGuildPersonIncomeTableViewCell.m in Sources */, E87E63F729AA1A5600EBE52B /* YuMi.xcdatamodeld in Sources */, diff --git a/YuMi/Global/YUMIMacroUitls.h b/YuMi/Global/YUMIMacroUitls.h index 9eb5a117..e778a30a 100644 --- a/YuMi/Global/YUMIMacroUitls.h +++ b/YuMi/Global/YUMIMacroUitls.h @@ -45,9 +45,6 @@ isPhoneXSeries = [[UIApplication sharedApplication] delegate].window.safeAreaIns #define kFontBold(font) [UIFont systemFontOfSize:kGetScaleWidth(font) weight:UIFontWeightBold] #define kFontHeavy(font) [UIFont systemFontOfSize:kGetScaleWidth(font) weight:UIFontWeightHeavy] - - - ///内置版本号 #define PI_App_Version @"1.0.24" ///渠道 @@ -55,8 +52,7 @@ isPhoneXSeries = [[UIApplication sharedApplication] delegate].window.safeAreaIns #define PI_Test_Flight @"TestFlight" #define ISTestFlight 0 ///正式环境 -//#define API_HOST_URL @"https://api.hfighting.com" -#define API_HOST_URL @"https://api.molistar.xyz" +#define API_HOST_URL @"https://api.hfighting.com" ///测试环境 #define API_HOST_TEST_URL @"http://beta.api.molistar.xyz" diff --git a/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.h b/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.h index 3cf1f9af..5f182341 100644 --- a/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.h +++ b/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.h @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN /// 上传头像 /// @param avatar 头像 - (void)uploadAvatar:(UIImage *)avatar; +- (void)uploadGifAvatar:(NSData *)data; ///获取地区列表 -(void)getAreaList; ///保存地区列表 diff --git a/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.m b/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.m index d6386c34..c4e5754b 100644 --- a/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.m +++ b/YuMi/Modules/YMMine/Presenter/XPMineUserInfoEditPresenter.m @@ -126,13 +126,27 @@ NSData *data = UIImageJPEGRepresentation(avatar, 0.5); NSString *format = [UIImage getImageTypeWithImageData:data]; NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format]; + @kWeakify(self); [[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) { + @kStrongify(self); [[self getView] uploadImageSuccess:key]; } failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) { }]; } +- (void)uploadGifAvatar:(NSData *)data { + NSString *format = [UIImage getImageTypeWithImageData:data]; + NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format]; + @kWeakify(self); + [[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) { + @kStrongify(self); + [[self getView] uploadImageSuccess:key]; + } failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) { + + }]; +} + ///获取地区列表 -(void)getAreaList{ [Api getAreaList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { diff --git a/YuMi/Modules/YMMine/View/MineInfo/XPMineUserInfoEditViewController.m b/YuMi/Modules/YMMine/View/MineInfo/XPMineUserInfoEditViewController.m index 9de8d923..dbbe1d3d 100644 --- a/YuMi/Modules/YMMine/View/MineInfo/XPMineUserInfoEditViewController.m +++ b/YuMi/Modules/YMMine/View/MineInfo/XPMineUserInfoEditViewController.m @@ -9,6 +9,7 @@ ///Third #import #import +#import ///Tool #import "TTPopup.h" @@ -32,10 +33,21 @@ #import "XPMineUserInfoAlbumViewController.h" #import "XPMineUserInfoRecordedSoundVC.h" +#import "AlbumResourcePickerViewController.h" UIKIT_EXTERN NSString * kUpdateSoundInfo; -@interface XPMineUserInfoEditViewController () +@interface XPMineUserInfoEditViewController ()< +UITableViewDelegate, +UITableViewDataSource, +XPMineUserInfoEditProtocol, +XPMineUserInfoDesViewControllerDelegate, +XPMineUserInfoNickViewControllerDelegate, +UIImagePickerControllerDelegate, +UINavigationControllerDelegate, +XPMineUserInfoDateViewDelegate, +XPMineUserInfoEditPickViewDelegate, +TZImagePickerControllerDelegate> ///列表 @property (nonatomic,strong) UITableView *tableView; ///数据源 @@ -108,12 +120,33 @@ UIKIT_EXTERN NSString * kUpdateSoundInfo; TTActionSheetConfig *photoLibrayConfig = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoEditViewController6") clickAction:^{ [YYUtility checkAssetsLibrayAvailable:^{ @strongify(self); - UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; - imagePicker.modalPresentationCapturesStatusBarAppearance = YES; - imagePicker.delegate = self; - imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; - imagePicker.allowsEditing = YES; - [self presentViewController:imagePicker animated:YES completion:NULL]; +// UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; +// imagePicker.modalPresentationCapturesStatusBarAppearance = YES; +// imagePicker.delegate = self; +// imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; +// imagePicker.allowsEditing = YES; + +// AlbumResourcePickerViewController *imagePicker = [[AlbumResourcePickerViewController alloc] init]; +// [self presentViewController:imagePicker animated:YES completion:NULL]; +// [imagePicker setDidSelectedAsset:^(PHAsset * _Nonnull asset) { +// +// }]; + + TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 + delegate:self]; + imagePickerVc.modalPresentationStyle = UIModalPresentationOverFullScreen; + imagePickerVc.allowPickingVideo = NO; + imagePickerVc.allowTakeVideo = NO; + imagePickerVc.allowPickingGif = YES; + imagePickerVc.allowCrop = YES; + CGFloat cropWidth = KScreenWidth; + imagePickerVc.cropRect = CGRectMake(0, (self.view.bounds.size.height - cropWidth) / 2, cropWidth, cropWidth); + imagePickerVc.naviBgColor = [DJDKMIMOMColor appCellBackgroundColor]; + imagePickerVc.naviTitleColor = [DJDKMIMOMColor mainTextColor]; + imagePickerVc.barItemTextColor = [DJDKMIMOMColor mainTextColor]; + [self presentViewController:imagePickerVc animated:YES completion:nil]; + + } denied:^{ @strongify(self); [self showNotPhoto:YMLocalizedString(@"XPMineUserInfoEditViewController7") content:YMLocalizedString(@"XPMineUserInfoEditViewController8")]; @@ -329,6 +362,52 @@ UIKIT_EXTERN NSString * kUpdateSoundInfo; } } +#pragma mark - TZImagePickerControllerDelegate +- (BOOL)isAssetCanBeDisplayed:(PHAsset *)asset { +// if ([[asset valueForKey:@"filename"] containsString:@"GIF"]) { +// // TODO: 新增参数,通过参数判断是否显示 GIF +// if (self.userInfo.userVipInfoVO.vipLevel > 2) { +// return NO; +// } +// } + return YES; // 其他类型的资源正常显示 +} + + + +- (void)imagePickerController:(TZImagePickerController *)picker + didFinishPickingPhotos:(NSArray *)photos + sourceAssets:(NSArray *)assets + isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto + infos:(NSArray *)infos { + PHAsset *sourceAsset = assets.firstObject; + if ([[sourceAsset valueForKey:@"filename"] containsString:@"GIF"]) { + @kWeakify(self); + dispatch_async(dispatch_get_main_queue(), ^{ + @kStrongify(self); + [self showLoading]; + [[PHImageManager defaultManager] requestImageDataForAsset:sourceAsset + options:nil + resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + [self.presenter uploadGifAvatar:imageData]; + }]; + [picker dismissViewControllerAnimated:YES completion:^{}]; + }); + } else { + @kWeakify(self); + dispatch_async(dispatch_get_main_queue(), ^{ + @kStrongify(self); + UIImage *croppedImage = photos.firstObject; // 选中的裁剪后的图片 + // 在这里处理裁剪后的图片 + if (croppedImage) { + [self showLoading]; + [self.presenter uploadAvatar:croppedImage]; + } + [picker dismissViewControllerAnimated:YES completion:^{}]; + }); + } +} + #pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { @@ -404,8 +483,12 @@ UIKIT_EXTERN NSString * kUpdateSoundInfo; } - (void)uploadImageSuccess:(NSString *)url { - [self hideHUD]; - [self.presenter complectionInfoWithAvatar:url nick:nil birth:nil userDesc:nil]; + @kWeakify(self); + dispatch_async(dispatch_get_main_queue(), ^{ + @kStrongify(self); + [self hideHUD]; + [self.presenter complectionInfoWithAvatar:url nick:nil birth:nil userDesc:nil]; + }); } #pragma mark - XPMineUserInfoEditPickView - (void)didClickSureActionWithArea:(NSString *)area{ diff --git a/YuMi/Modules/YMRoom/View/AnimationView/LuckyGiftWinningBannerView.m b/YuMi/Modules/YMRoom/View/AnimationView/LuckyGiftWinningBannerView.m index 71932424..057ca386 100644 --- a/YuMi/Modules/YMRoom/View/AnimationView/LuckyGiftWinningBannerView.m +++ b/YuMi/Modules/YMRoom/View/AnimationView/LuckyGiftWinningBannerView.m @@ -15,6 +15,7 @@ @interface LuckyGiftWinningBannerViewModel : PIBaseModel +// 会命中混淆,model 单独出来 @property (nonatomic, copy) NSString *times; @property (nonatomic, copy) NSString *avatar; @property (nonatomic, copy) NSString *coins; diff --git a/YuMi/Modules/YMWeb/XPWebViewController.m b/YuMi/Modules/YMWeb/XPWebViewController.m index 79545cf3..430c34a8 100644 --- a/YuMi/Modules/YMWeb/XPWebViewController.m +++ b/YuMi/Modules/YMWeb/XPWebViewController.m @@ -280,7 +280,7 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback"; if (self.urlLoadCompleted) { self.urlLoadCompleted(YES, nil); } - +#if DEBUG NSString *fileName = @"vconsole.min.js"; // 你要查找的文件名 NSString *directory = [[NSBundle mainBundle] resourcePath]; @@ -304,6 +304,7 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback"; NSString *initVConsoleScript = @"var vConsole = new VConsole();"; [webView evaluateJavaScript:initVConsoleScript completionHandler:nil]; } +#endif } //加载失败 diff --git a/YuMi/Tools/File/AlbumResourcePickerViewController.h b/YuMi/Tools/File/AlbumResourcePickerViewController.h new file mode 100644 index 00000000..1a10c2a8 --- /dev/null +++ b/YuMi/Tools/File/AlbumResourcePickerViewController.h @@ -0,0 +1,19 @@ +// +// AlbumResourcePickerViewController.h +// YuMi +// +// Created by P on 2024/10/18. +// + +#import + +@class PHAsset; +NS_ASSUME_NONNULL_BEGIN + +@interface AlbumResourcePickerViewController : UIViewController + +@property (nonatomic, copy) void(^didSelectedAsset)(PHAsset *asset); + +@end + +NS_ASSUME_NONNULL_END diff --git a/YuMi/Tools/File/AlbumResourcePickerViewController.m b/YuMi/Tools/File/AlbumResourcePickerViewController.m new file mode 100644 index 00000000..f97b079b --- /dev/null +++ b/YuMi/Tools/File/AlbumResourcePickerViewController.m @@ -0,0 +1,281 @@ +// +// AlbumResourcePickerViewController.m +// YuMi +// +// Created by P on 2024/10/18. +// + +#import "AlbumResourcePickerViewController.h" + +#import +#import + +#import "YYUtility.h" + +@interface ImageDetailViewController : UIViewController +@property (nonatomic, strong) UIImage *image; // 用于显示静态图片 +@property (nonatomic, strong) NSData *gifData; // 用于显示 GIF 数据 +@end + +@implementation ImageDetailViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.view.backgroundColor = [UIColor blackColor]; // 背景颜色为黑色 + + if (self.gifData) { + // 如果是 GIF 动画 + FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:self.gifData]; + FLAnimatedImageView *animatedImageView = [[FLAnimatedImageView alloc] initWithFrame:self.view.bounds]; + animatedImageView.animatedImage = animatedImage; + animatedImageView.contentMode = UIViewContentModeScaleAspectFit; + [self.view addSubview:animatedImageView]; + } else if (self.image) { + // 如果是静态图片 + UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; + imageView.image = self.image; + imageView.contentMode = UIViewContentModeScaleAspectFit; + [self.view addSubview:imageView]; + } + + [self setupToolArea]; + + // 添加关闭按钮 + UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem]; + [closeButton setTitle:@"关闭" forState:UIControlStateNormal]; + closeButton.frame = CGRectMake(20, 40, 60, 30); + [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [closeButton addTarget:self action:@selector(closeButtonTapped) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:closeButton]; +} + +- (void)setupToolArea { + UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 44)]; + titleLabel.text = @"选取图片"; +// titleLabel.backgroundColor = [UIColor c]; +} + +// 关闭按钮点击事件 +- (void)closeButtonTapped { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +@end + + +@interface AlbumResourceCollectionCell : UICollectionViewCell + +@property (nonatomic, strong) FLAnimatedImageView *imageView; + +- (void)setupGifImage:(NSData *)data; +- (void)setupImage:(PHAsset *)asset; + +@end + +@implementation AlbumResourceCollectionCell + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + [self.contentView addSubview:self.imageView]; + [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.mas_equalTo(self.contentView); + }]; + } + return self; +} + +- (FLAnimatedImageView *)imageView { + if (!_imageView) { + _imageView = [[FLAnimatedImageView alloc] init]; + _imageView.contentMode = UIViewContentModeScaleAspectFill; + _imageView.clipsToBounds = YES; + } + return _imageView; +} +- (void)setupGifImage:(NSData *)data { + FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:data]; + self.imageView.animatedImage = animatedImage; +} + +- (void)setupImage:(PHAsset *)asset { + @kWeakify(self); + [[PHImageManager defaultManager] requestImageForAsset:asset + targetSize:CGSizeMake(250, 250) + contentMode:PHImageContentModeAspectFill + options:nil + resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { + @kStrongify(self); + self.imageView.image = result; + }]; +} + +@end + +@interface AlbumResourcePickerViewController () + +@property (nonatomic, strong) UICollectionView *collectionView; +@property (nonatomic, strong) PHFetchResult *allPhotos; +@property (nonatomic, assign) CGSize cellSize; +@property (nonatomic, assign) CGFloat cellSpace; + +@end + +@implementation AlbumResourcePickerViewController + ++ (void)checkAuthorization:(void(^)(BOOL authorized))result { + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { + if (result) { + result(status == PHAuthorizationStatusAuthorized); + } + }]; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + [self calSize]; + [self setupCollectionView]; + [self fetchAllPhotos]; +} + +- (void)calSize { + self.cellSpace = 2; + CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width; + CGFloat width = (screenWidth - self.cellSpace * self.cellSpace) / 3; + self.cellSize = CGSizeMake(width, width); +} + +- (void)fetchAllPhotos { + PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init]; + fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; + + // 获取所有类型的资源 + self.allPhotos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage + options:fetchOptions]; + + // 刷新 UICollectionView + dispatch_async(dispatch_get_main_queue(), ^{ + [self.collectionView reloadData]; + }); +} + +- (void)handleAsset:(PHAsset *)asset { + // 使用 PHImageManager 来请求图像数据 + [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + NSLog(@"%@", info); + if ([dataUTI isEqualToString:@"com.compuserve.gif"]) { + // 是 GIF 文件,处理 GIF 数据 + FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; + FLAnimatedImageView *animatedImageView = [[FLAnimatedImageView alloc] init]; + animatedImageView.animatedImage = animatedImage; +// [self displayAnimatedImageView:animatedImageView]; + } else { + // 是普通图片 + UIImage *image = [UIImage imageWithData:imageData]; + [self displayStaticImage:image]; + } + }]; +} + +- (void)displayAnimatedImageView:(FLAnimatedImageView *)animatedImageView { + animatedImageView.frame = CGRectMake(0, 0, 300, 300); // 设置合适的 frame + [self.view addSubview:animatedImageView]; +} + +- (void)displayStaticImage:(UIImage *)image { + UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; + imageView.frame = CGRectMake(0, 0, 300, 300); // 设置合适的 frame + [self.view addSubview:imageView]; +} + +- (void)setupCollectionView { + UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; + layout.minimumInteritemSpacing = self.cellSpace; + layout.minimumLineSpacing = self.cellSpace; + layout.itemSize = self.cellSize; + + UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; + collectionView.delegate = self; + collectionView.dataSource = self; + + [collectionView registerClass:[AlbumResourceCollectionCell class] forCellWithReuseIdentifier:@"PhotoCell"]; + [self.view addSubview:collectionView]; +} + +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + return self.allPhotos.count; // 返回相册中的资源数量 +} + +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + AlbumResourceCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath]; + + PHAsset *asset = self.allPhotos[indexPath.item]; + + // 使用 PHImageManager 来请求图像数据,判断是否为 GIF + [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + +// [cell setupImage:imageData isGif:[dataUTI isEqualToString:@"com.compuserve.gif"]]; + + if ([dataUTI isEqualToString:@"com.compuserve.gif"]) { + [cell setupGifImage:imageData]; +// [cell setupImage:imageData isGif:YES]; + } else { + [cell setupImage:asset]; +// [cell setupImage:imageData isGif:NO]; +// // 是普通静态图片 +// [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(100, 100) contentMode:PHImageContentModeAspectFill options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { +// UIImageView *imageView = [[UIImageView alloc] initWithImage:result]; +// imageView.frame = cell.contentView.bounds; +// [cell.contentView addSubview:imageView]; +// }]; + } + }]; + + return cell; +} + +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { + PHAsset *asset = self.allPhotos[indexPath.item]; + + // 使用 PHImageManager 来请求图像数据 + [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { + + // 创建 ImageDetailViewController 并传递图片数据 + ImageDetailViewController *detailVC = [[ImageDetailViewController alloc] init]; + + if ([dataUTI isEqualToString:@"com.compuserve.gif"]) { + // 是 GIF 文件,传递 GIF 数据 + detailVC.gifData = imageData; + } else { + // 是静态图片,传递 UIImage + UIImage *image = [UIImage imageWithData:imageData]; + detailVC.image = image; + } + + // 弹出全屏显示图片的视图控制器 + [self presentViewController:detailVC animated:YES completion:nil]; + }]; + + if (self.didSelectedAsset) { + self.didSelectedAsset(asset); + } +// // 使用 PHImageManager 来请求图像数据 +// [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { +// if ([dataUTI isEqualToString:@"com.compuserve.gif"]) { +// // 是 GIF 文件,播放 GIF 动画 +// FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData]; +// FLAnimatedImageView *animatedImageView = [[FLAnimatedImageView alloc] init]; +// animatedImageView.animatedImage = animatedImage; +// [self displayAnimatedImageView:animatedImageView]; +// } else { +// // 是静态图片 +// UIImage *image = [UIImage imageWithData:imageData]; +// [self displayStaticImage:image]; +// } +// }]; +} + + +@end