Commit 0fa012c4 authored by admin's avatar admin

完成图片缓存功能

parent 7653df0f
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#define Url_h #define Url_h
// url 测试环境 // url 测试环境
// #define kRedStarURL @"http://218.244.151.129:7580/" #define kRedStarURL @"http://218.244.151.129:7580/"
// 正式环境 // 正式环境
#define kRedStarURL @"http://219.235.234.225:7580/" // #define kRedStarURL @"http://219.235.234.225:7580/"
// 最新正式环境 // 最新正式环境
//#define kRedStarURL @"http://219.235.234.212:7580/" //#define kRedStarURL @"http://219.235.234.212:7580/"
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
typedef NS_ENUM(NSInteger, PictureSaveMode) { typedef NS_ENUM(NSInteger, PictureSaveMode) {
PictureNetWorkMode = 0, PictureNetWorkMode = 0,
PictureLocalMode = 1 PictureLocalMode = 1,
PictureSpecialMode = 2
}; };
@interface LargePictureViewController : UIViewController<UIScrollViewDelegate>{ @interface LargePictureViewController : UIViewController<UIScrollViewDelegate>{
...@@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, PictureSaveMode) { ...@@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, PictureSaveMode) {
@property (nonatomic, strong) UIScrollView *imageScrollView; @property (nonatomic, strong) UIScrollView *imageScrollView;
@property (nonatomic, assign) PictureSaveMode pictureSaveMode; @property (nonatomic, assign) PictureSaveMode pictureSaveMode;
@property (nonatomic, strong) NSString *uuid;
- (CGRect)zoomRectForScale:(float)scale inView:(UIScrollView*)scrollView withCenter:(CGPoint)center; - (CGRect)zoomRectForScale:(float)scale inView:(UIScrollView*)scrollView withCenter:(CGPoint)center;
@end @end
...@@ -63,8 +63,13 @@ ...@@ -63,8 +63,13 @@
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath]; UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
imageview.image = image; imageview.image = image;
} else { } else if (self.pictureSaveMode == PictureNetWorkMode) {
[imageview sd_setImageWithURL:_allImageArray[i] placeholderImage:[UIImage imageNamed:@"default_pic"]]; [imageview sd_setImageWithURL:_allImageArray[i] placeholderImage:[UIImage imageNamed:@"default_pic"]];
} else {
NSString *imageName = _allImageArray[i];
NSString *fullPath = [[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:_uuid] stringByAppendingPathComponent:imageName];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
imageview.image = image;
} }
imageview.frame = CGRectMake(20, 0, kScreenWidth, (kScreenHeight - 20)); imageview.frame = CGRectMake(20, 0, kScreenWidth, (kScreenHeight - 20));
imageview.userInteractionEnabled = YES; imageview.userInteractionEnabled = YES;
......
...@@ -167,6 +167,7 @@ ...@@ -167,6 +167,7 @@
LargePictureViewController *largeVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
largeVC.index = imageView.tag - 1116; largeVC.index = imageView.tag - 1116;
largeVC.allImageArray = _allImageURL; largeVC.allImageArray = _allImageURL;
largeVC.pictureSaveMode = PictureNetWorkMode;
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
} }
...@@ -175,6 +176,7 @@ ...@@ -175,6 +176,7 @@
LargePictureViewController *largeVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
largeVC.index = sender.tag - 1117; largeVC.index = sender.tag - 1117;
largeVC.allImageArray = _allStoreImageURL; largeVC.allImageArray = _allStoreImageURL;
largeVC.pictureSaveMode = PictureNetWorkMode;
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
} }
......
...@@ -278,6 +278,8 @@ ...@@ -278,6 +278,8 @@
UIImageView *imageView = (UIImageView *)sender.view; UIImageView *imageView = (UIImageView *)sender.view;
LargePictureViewController *largeVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
largeVC.index = imageView.tag - 1115; largeVC.index = imageView.tag - 1115;
largeVC.pictureSaveMode = PictureNetWorkMode;
largeVC.allImageArray = _allImageURL; largeVC.allImageArray = _allImageURL;
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
@property (nonatomic, strong) NSMutableArray *imageNameArray; @property (nonatomic, strong) NSMutableArray *imageNameArray;
@property (nonatomic, strong) NSLayoutConstraint *tableBottom; @property (nonatomic, strong) NSLayoutConstraint *tableBottom;
@property (nonatomic, strong) NSLayoutConstraint *tableTop; @property (nonatomic, strong) NSLayoutConstraint *tableTop;
@property (nonatomic, assign) int rowNumber; @property (nonatomic, assign) NSInteger rowNumber;
@property (nonatomic, strong) UIButton *deleteButton; @property (nonatomic, strong) UIButton *deleteButton;
@end @end
...@@ -71,6 +71,28 @@ ...@@ -71,6 +71,28 @@
_rowNumber = 2; _rowNumber = 2;
self.view.backgroundColor = [UIColor colorWithRed:239 / 255.0 green:239 / 255.0 blue:239 / 255.0 alpha:239 / 255.0]; self.view.backgroundColor = [UIColor colorWithRed:239 / 255.0 green:239 / 255.0 blue:239 / 255.0 alpha:239 / 255.0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
if ([fileManager fileExistsAtPath:path]) {
NSDirectoryEnumerator *myDirectoryEnumerator = [fileManager enumeratorAtPath:path];
while((path = [myDirectoryEnumerator nextObject])!=nil) {
if (![_imageNameArray containsObject:path]) {
[_imageNameArray addObject:path];
}
}
if (_imageNameArray.count % 2 == 1) {
_rowNumber = _rowNumber + (_imageNameArray.count + 1) / 2 - 1;
} else {
_rowNumber = _rowNumber + _imageNameArray.count / 2 ;
}
[self.tableView reloadData];
}
} }
...@@ -101,7 +123,8 @@ ...@@ -101,7 +123,8 @@
LargePictureViewController *largeVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
largeVC.index = sender.tag - kPhotoTag; largeVC.index = sender.tag - kPhotoTag;
largeVC.allImageArray = _imageNameArray; largeVC.allImageArray = _imageNameArray;
largeVC.pictureSaveMode = PictureLocalMode; largeVC.pictureSaveMode = PictureSpecialMode;
largeVC.uuid = [NSString stringWithFormat:@"%@", _taskModel.uuid];
[self removeDeleteButton]; [self removeDeleteButton];
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
...@@ -168,10 +191,23 @@ ...@@ -168,10 +191,23 @@
[_imageNameArray addObject:imageName]; [_imageNameArray addObject:imageName];
// 获取沙盒目录 // 获取沙盒目录
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; // NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSString *imagePath = [path stringByAppendingPathComponent:imageName];
BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
if (bo) {
// 将图片写入文件 // 将图片写入文件
[imageData writeToFile:fullPath atomically:NO]; [imageData writeToFile:imagePath atomically:NO];
imageData = nil; imageData = nil;
} else {
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:path error:nil];
}
} }
#pragma mark - TableView Delegate/DataSource #pragma mark - TableView Delegate/DataSource
...@@ -205,6 +241,7 @@ ...@@ -205,6 +241,7 @@
} }
return cell; return cell;
} else if (indexPath.row == _rowNumber - 1) { } else if (indexPath.row == _rowNumber - 1) {
NSLog(@"index.row === %ld", indexPath.row);
if ((_imageNameArray.count + 1) % 2 == 0) { if ((_imageNameArray.count + 1) % 2 == 0) {
NSString *identifier = [NSString stringWithFormat:@"InspectaddPicCell"]; NSString *identifier = [NSString stringWithFormat:@"InspectaddPicCell"];
InspectPicAddCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier]; InspectPicAddCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
...@@ -212,7 +249,11 @@ ...@@ -212,7 +249,11 @@
cell = [[InspectPicAddCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; cell = [[InspectPicAddCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
} }
NSString *imageName = _imageNameArray[_imageNameArray.count - 1]; NSString *imageName = _imageNameArray[_imageNameArray.count - 1];
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; //NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSString *fullPath = [path stringByAppendingPathComponent:imageName];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath]; UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)]; UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
...@@ -250,13 +291,23 @@ ...@@ -250,13 +291,23 @@
cell = [[InpectPictureCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; cell = [[InpectPictureCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
} }
NSString *imageName0 = _imageNameArray[(indexPath.row - 1) * 2]; NSString *imageName0 = _imageNameArray[(indexPath.row - 1) * 2];
NSString *fullPath0 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName0]; // NSString *fullPath0 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName0];
NSLog(@"qqqqw==== %ld", (indexPath.row - 1) * 2 );
NSString *path0 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSString *fullPath0 = [path0 stringByAppendingPathComponent:imageName0];
UIImage *image0 = [UIImage imageWithContentsOfFile:fullPath0]; UIImage *image0 = [UIImage imageWithContentsOfFile:fullPath0];
UIImage *image00 = [UIImage image:image0 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)]; UIImage *image00 = [UIImage image:image0 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
[cell.photoButton1 setImage:image00 forState:UIControlStateNormal]; [cell.photoButton1 setImage:image00 forState:UIControlStateNormal];
NSLog(@"qqqq==== %ld", (indexPath.row - 1) * 2 + 1);
NSString *imageName1 = _imageNameArray[(indexPath.row - 1) * 2 + 1]; NSString *imageName1 = _imageNameArray[(indexPath.row - 1) * 2 + 1];
NSString *fullPath1 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName1]; // NSString *fullPath1 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName1];
NSString *path1 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSString *fullPath1 = [path1 stringByAppendingPathComponent:imageName1];
UIImage *image1 = [UIImage imageWithContentsOfFile:fullPath1]; UIImage *image1 = [UIImage imageWithContentsOfFile:fullPath1];
UIImage *image11 = [UIImage image:image1 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)]; UIImage *image11 = [UIImage image:image1 fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
...@@ -355,7 +406,11 @@ ...@@ -355,7 +406,11 @@
NSMutableArray *imageArray = [NSMutableArray array]; NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 0; i < _imageNameArray.count; i++) { for (int i = 0; i < _imageNameArray.count; i++) {
NSString *imageName = _imageNameArray[i]; NSString *imageName = _imageNameArray[i];
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; //NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSString *fullPath = [path stringByAppendingPathComponent:imageName];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath]; UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
NSData *imageData = UIImageJPEGRepresentation(image, 0.01); NSData *imageData = UIImageJPEGRepresentation(image, 0.01);
NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0]; NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0];
...@@ -391,6 +446,19 @@ ...@@ -391,6 +446,19 @@
alert.delegate = self; alert.delegate = self;
alert.tag = 39429234; alert.tag = 39429234;
[alert show]; [alert show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",_taskModel.uuid]];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
for (NSString *p in files) {
NSError *error;
NSString *paths = [path stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:paths]) {
[[NSFileManager defaultManager] removeItemAtPath:paths error:&error];
}
}
});
} }
[MBProgressHUD hideHUDForView:self.view animated:YES]; [MBProgressHUD hideHUDForView:self.view animated:YES];
......
...@@ -130,6 +130,7 @@ ...@@ -130,6 +130,7 @@
LargePictureViewController *largeVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
largeVC.index = imageView.tag - 1113; largeVC.index = imageView.tag - 1113;
largeVC.allImageArray = _allImageURL; largeVC.allImageArray = _allImageURL;
largeVC.pictureSaveMode = PictureNetWorkMode;
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
// CheckPicViewController *checkVC = [[CheckPicViewController alloc] init]; // CheckPicViewController *checkVC = [[CheckPicViewController alloc] init];
......
...@@ -169,6 +169,7 @@ ...@@ -169,6 +169,7 @@
{ {
LargePictureViewController *largePVC = [[LargePictureViewController alloc] init]; LargePictureViewController *largePVC = [[LargePictureViewController alloc] init];
largePVC.allImageArray = _allImageArray; largePVC.allImageArray = _allImageArray;
largePVC.pictureSaveMode = PictureNetWorkMode;
largePVC.index = btn.tag - 1112; largePVC.index = btn.tag - 1112;
[self.navigationController pushViewController:largePVC animated:YES]; [self.navigationController pushViewController:largePVC animated:YES];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment