You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
6.8 KiB
192 lines
6.8 KiB
1 year ago
|
//
|
||
|
// PhotosViewController.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by WeiChaoZheng on 2018/6/19.
|
||
|
// Copyright © 2018年 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "PhotosViewController.h"
|
||
|
|
||
|
@interface PhotosViewController ()
|
||
|
@property (nonatomic, strong) UILabel * showLabel;
|
||
|
@end
|
||
|
|
||
|
|
||
|
@implementation PhotosViewController
|
||
|
-(void)setCurrentIndex:(NSInteger)currentIndex{
|
||
|
_currentIndex = currentIndex;
|
||
|
NSString *textCount = [NSString stringWithFormat:@"%zd / %zd",_currentIndex+1,self.dataSouce.count];
|
||
|
self.showLabel.text = textCount;
|
||
|
}
|
||
|
-(NSArray *)dataSouce{
|
||
|
if(!_dataSouce){
|
||
|
_dataSouce = [NSMutableArray array];
|
||
|
}
|
||
|
return _dataSouce;
|
||
|
}
|
||
|
-(NSMutableArray *)dataViews{
|
||
|
if(!_dataViews){
|
||
|
_dataViews = [NSMutableArray array];
|
||
|
}
|
||
|
return _dataViews;
|
||
|
}
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
self.view.backgroundColor = [UIColor blackColor];
|
||
|
[self initView];
|
||
|
[self reloadData];
|
||
|
|
||
|
}
|
||
|
|
||
|
-(void) initView{
|
||
|
|
||
|
//右侧导航栏添加个按钮 删除模式
|
||
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed:@"icon_delete"]
|
||
|
style:UIBarButtonItemStylePlain
|
||
|
target:self
|
||
|
action:@selector(deletePhotoAction)];
|
||
|
|
||
|
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SWIDTH, SHEIGHT-64)];
|
||
|
self.scrollView.delegate = self;
|
||
|
[self.scrollView setPagingEnabled:YES];
|
||
|
[self.scrollView setBouncesZoom:YES];
|
||
|
///设置最大和最小缩放比例
|
||
|
self.scrollView.minimumZoomScale = 1.0;
|
||
|
self.scrollView.maximumZoomScale = 2.0;
|
||
|
[self.view addSubview:self.scrollView];
|
||
|
|
||
|
self.showLabel = [[UILabel alloc] initWithFrame:CGRectMake((SWIDTH-100)/2,SHEIGHT-64-50-10, 100, 50)];
|
||
|
self.showLabel.font = [UIFont systemFontOfSize:17];
|
||
|
self.showLabel.textAlignment = 1;
|
||
|
self.showLabel.textColor = [UIColor whiteColor];
|
||
|
[self.view addSubview: self.showLabel];
|
||
|
|
||
|
}
|
||
|
|
||
|
-(void)reloadData{
|
||
|
for (Photo *photo in self.dataSouce) {
|
||
|
photo.isSelect = NO;
|
||
|
}
|
||
|
if(self.dataSouce.count == 0){
|
||
|
[self.navigationController popViewControllerAnimated:YES];
|
||
|
return;
|
||
|
}
|
||
|
if (self.dataViews.count > 0) {
|
||
|
for (UIView* view in self.dataViews) {
|
||
|
[view removeFromSuperview];
|
||
|
}
|
||
|
[self.dataViews removeAllObjects];
|
||
|
}
|
||
|
if(self.dataSouce.count != 0){
|
||
|
NSInteger count = self.dataSouce.count;
|
||
|
for (int i = 0; i < count ; i++) {
|
||
|
// Photo *photo = self.dataSouce[i];
|
||
|
// XLZoomingScrollView * view = [[XLZoomingScrollView alloc] initWithFrame:CGRectMake(i*SWIDTH, 0, SWIDTH, SHEIGHT-64)];
|
||
|
//// [view.contentImage sd_setImageWithURL:[NSURL URLWithString:photo.url]];
|
||
|
// [self.dataViews addObject:view];
|
||
|
// [self.scrollView addSubview:view];
|
||
|
}
|
||
|
|
||
|
self.scrollView.contentSize = CGSizeMake(self.dataSouce.count * SWIDTH, 0);
|
||
|
[self.scrollView setContentOffset:CGPointMake(self.currentIndex*SWIDTH, 0) animated:NO];
|
||
|
[self scrollViewWillBeginDragging:self.scrollView];
|
||
|
// [self setDataWithIndex:self.currentIndex];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
删除照片
|
||
|
*/
|
||
|
-(void)deletePhotoAction{
|
||
|
WEAKSELF
|
||
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"注意" message:@"确认删除图片?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
||
|
|
||
|
@try {
|
||
|
Photo *photo = weakSelf.dataSouce[self.currentIndex];
|
||
|
NSMutableArray *arr = [NSMutableArray arrayWithArray:@[photo]];
|
||
|
[weakSelf deleteActionWith:arr];
|
||
|
} @catch (NSException *exception) {
|
||
|
|
||
|
}
|
||
|
|
||
|
} cancelHandler:nil destructiveHandler:nil];
|
||
|
|
||
|
[alertView showAnimated:YES completionHandler:nil];
|
||
|
}
|
||
|
|
||
|
-(void)deleteActionWith:(NSMutableArray *)arr{
|
||
|
WEAKSELF
|
||
|
[Photo deletePhotos:arr
|
||
|
success:^{
|
||
|
//删除成功 刷新数据
|
||
|
NSMutableArray *dataArr = [NSMutableArray arrayWithArray:weakSelf.dataSouce];
|
||
|
[dataArr removeObjectAtIndex:weakSelf.currentIndex];
|
||
|
weakSelf.dataSouce = dataArr;
|
||
|
// [weakSelf.dataSouce removeObjectAtIndex:weakSelf.currentIndex];
|
||
|
|
||
|
if(weakSelf.dataSouce != 0){
|
||
|
if(weakSelf.currentIndex > 0 && weakSelf.dataSouce.count > 1){
|
||
|
weakSelf.currentIndex -= 1;
|
||
|
}else{
|
||
|
weakSelf.currentIndex = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[weakSelf reloadData];
|
||
|
} failure:^{
|
||
|
|
||
|
}];
|
||
|
}
|
||
|
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
|
||
|
//当前的标识
|
||
|
int index =(int)(scrollView.contentOffset.x / SWIDTH);
|
||
|
self.currentIndex = index;
|
||
|
[self setDataWithIndex:index];
|
||
|
}
|
||
|
|
||
|
-(void)setDataWithIndex:(int)index
|
||
|
{
|
||
|
// if(self.dataViews.count > index){
|
||
|
// if(index > 1){ //表示左边图 存在
|
||
|
// XLZoomingScrollView *view1 = self.dataViews[index-1];
|
||
|
// Photo *photo1 = self.dataSouce[index-1];
|
||
|
// if(!photo1.isSelect){
|
||
|
// [view1 setShowHighQualityImageWithURL:[NSURL URLWithString:photo1.url] placeholderImage:nil];
|
||
|
// photo1.isSelect = YES;
|
||
|
// }
|
||
|
//
|
||
|
// }
|
||
|
// if(index+1 < self.dataViews.count-1){ //表示右边图 存在
|
||
|
// XLZoomingScrollView *view3 = self.dataViews[index+1];
|
||
|
// Photo *photo3 = self.dataSouce[index+1];
|
||
|
// if(!photo3.isSelect){
|
||
|
// [view3 setShowHighQualityImageWithURL:[NSURL URLWithString:photo3.url] placeholderImage:nil];
|
||
|
// photo3.isSelect = YES;
|
||
|
// }
|
||
|
// }
|
||
|
//
|
||
|
// XLZoomingScrollView *view2 = self.dataViews[index];
|
||
|
// Photo *photo2 = self.dataSouce[index];
|
||
|
// if(!photo2.isSelect){
|
||
|
// [view2 setShowHighQualityImageWithURL:[NSURL URLWithString:photo2.url] placeholderImage:nil];
|
||
|
// photo2.isSelect = YES;
|
||
|
// }
|
||
|
// NSTimeInterval time = [photo2.time doubleValue];
|
||
|
// NSDateFormatter *formatter = [NSDateFormatter new];
|
||
|
// [formatter setDateFormat:@"MM月dd日 HH:mm:ss"];
|
||
|
// self.title = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:time]];
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
|
||
|
//当前的标识
|
||
|
int index =(int)(scrollView.contentOffset.x / SWIDTH);
|
||
|
self.currentIndex = index;
|
||
|
[self setDataWithIndex:index];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@end
|