chore: Initial clean commit

- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
This commit is contained in:
edwinQQQ
2025-10-09 16:19:14 +08:00
commit a35a711be6
5582 changed files with 408913 additions and 0 deletions

View File

@@ -0,0 +1,281 @@
//
// AlbumResourcePickerViewController.m
// YuMi
//
// Created by P on 2024/10/18.
//
#import "AlbumResourcePickerViewController.h"
#import <Photos/Photos.h>
#import <SDWebImageFLPlugin/SDWebImageFLPlugin.h>
#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 () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@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