Commit 54200797 authored by admin's avatar admin

长按删除照片

parent e639546a
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
@property (nonatomic, assign) int rowNumber; @property (nonatomic, assign) int rowNumber;
@property (nonatomic, strong) NSLayoutConstraint *tableBottom; @property (nonatomic, strong) NSLayoutConstraint *tableBottom;
@property (nonatomic, strong) NSLayoutConstraint *tableTop; @property (nonatomic, strong) NSLayoutConstraint *tableTop;
@property (nonatomic, strong) UIButton *deleteButton;
@end @end
@implementation LookOnLineDetailViewController @implementation LookOnLineDetailViewController
...@@ -160,6 +163,10 @@ ...@@ -160,6 +163,10 @@
lager.index = sender.tag - 1118; lager.index = sender.tag - 1118;
lager.pictureSaveMode = PictureLocalMode; lager.pictureSaveMode = PictureLocalMode;
lager.allImageArray = _imageNameArray; lager.allImageArray = _imageNameArray;
[self removeDeleteButton];
[self.navigationController pushViewController:lager animated:YES]; [self.navigationController pushViewController:lager animated:YES];
} }
...@@ -322,9 +329,9 @@ ...@@ -322,9 +329,9 @@
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
// UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)]; // 添加长按手势
// [cell.photoButton1 addGestureRecognizer:longGR]; UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
// cell.contentView.backgroundColor = [UIColor orangeColor]; [cell.photoButton1 addGestureRecognizer:longGR];
return cell; return cell;
} else { } else {
...@@ -365,11 +372,12 @@ ...@@ -365,11 +372,12 @@
[cell.photoButton2 setImage:image11 forState:UIControlStateNormal]; [cell.photoButton2 setImage:image11 forState:UIControlStateNormal];
// 添加长按手势
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
// UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)]; UILongPressGestureRecognizer *longGR2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
// [cell.photoButton2 addGestureRecognizer:longGR2];
// [cell.photoButton1 addGestureRecognizer:longGR];
// [cell.photoButton2 addGestureRecognizer:longGR];
return cell; return cell;
} }
...@@ -377,27 +385,34 @@ ...@@ -377,27 +385,34 @@
} }
- (void)longClick:(UIGestureRecognizer *)longGR - (void)longClick:(UIGestureRecognizer *)longGR {
{
if (longGR.state == UIGestureRecognizerStateBegan) { // 获取到点击的显示图片的按钮
UIButton *showButton = (UIButton *)longGR.view;
// 获取到点击的显示图片的按钮 NSLog(@"我长按了第%ld张图片", (showButton.tag - 1118));
UIButton *showButton = (UIButton *)longGR.view;
if (_deleteButton) {
// 创建长按删除的按钮 [_deleteButton removeFromSuperview];
_deleteButton = nil;
}
if (!_deleteButton) {
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.tag = 5521 + (showButton.tag - 1118); deleteButton.tag = 5521 + (showButton.tag - 1118);
deleteButton.backgroundColor = [UIColor redColor]; [deleteButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
deleteButton.backgroundColor = [UIColor whiteColor];
deleteButton.bounds = CGRectMake(0, 0, 20, 20); deleteButton.bounds = CGRectMake(0, 0, 20, 20);
[deleteButton addTarget:self action:@selector(deletePicture:) forControlEvents:UIControlEventTouchUpInside]; [deleteButton addTarget:self action:@selector(deletePicture:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.frame = CGRectMake(showButton.frame.size.width - deleteButton.frame.size.width, 0, deleteButton.frame.size.width, deleteButton.frame.size.height); deleteButton.frame = CGRectMake(showButton.frame.size.width - deleteButton.frame.size.width, 0, deleteButton.frame.size.width, deleteButton.frame.size.height);
[showButton addSubview:deleteButton]; [showButton addSubview:deleteButton];
_deleteButton = deleteButton;
} }
} }
// 删除图片 // 删除图片
- (void)deletePicture:(UIButton *)button - (void)deletePicture:(UIButton *)button
{ {
NSLog(@"从imageName中删除了第%ld张图片",(button.tag - 5521));
// 从存放所有Image的数组里移除当前点击的Image // 从存放所有Image的数组里移除当前点击的Image
[self.imageNameArray removeObjectAtIndex:(button.tag - 5521)]; [self.imageNameArray removeObjectAtIndex:(button.tag - 5521)];
...@@ -407,7 +422,18 @@ ...@@ -407,7 +422,18 @@
} else { } else {
[self.tableView reloadData]; [self.tableView reloadData];
} }
[button removeFromSuperview];
button = nil;
[self removeDeleteButton];
}
- (void)removeDeleteButton {
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
} }
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
......
...@@ -58,6 +58,9 @@ ...@@ -58,6 +58,9 @@
@property (nonatomic) BOOL isComplete; @property (nonatomic) BOOL isComplete;
@property (nonatomic) BOOL isLoad; @property (nonatomic) BOOL isLoad;
@property (nonatomic, strong) NSMutableDictionary *groupUuidDict; @property (nonatomic, strong) NSMutableDictionary *groupUuidDict;
@property (nonatomic, strong) UIButton *deleteButton;
@end @end
@implementation AddQuestionViewController @implementation AddQuestionViewController
...@@ -193,6 +196,7 @@ ...@@ -193,6 +196,7 @@
lager.index = sender.tag - kPhotoTag; lager.index = sender.tag - kPhotoTag;
lager.pictureSaveMode = PictureLocalMode; lager.pictureSaveMode = PictureLocalMode;
lager.allImageArray = _imageNameArray; lager.allImageArray = _imageNameArray;
[self removeDeleteButton];
[self.navigationController pushViewController:lager animated:YES]; [self.navigationController pushViewController:lager animated:YES];
// CheckPicViewController *checkVC = [[CheckPicViewController alloc] init]; // CheckPicViewController *checkVC = [[CheckPicViewController alloc] init];
...@@ -216,7 +220,7 @@ ...@@ -216,7 +220,7 @@
_selectActionSheet.delegate = self; _selectActionSheet.delegate = self;
_selectActionSheet.tag = 999283; _selectActionSheet.tag = 999283;
[_selectActionSheet showInView:self.view]; [_selectActionSheet showInView:self.view];
[self removeDeleteButton];
if (sender.tag == 2201) { if (sender.tag == 2201) {
_rowNumber++; _rowNumber++;
...@@ -238,6 +242,57 @@ ...@@ -238,6 +242,57 @@
[imageData writeToFile:fullPath atomically:NO]; [imageData writeToFile:fullPath atomically:NO];
} }
- (void)longClick:(UIGestureRecognizer *)longGR {
// 获取到点击的显示图片的按钮
UIButton *showButton = (UIButton *)longGR.view;
NSLog(@"我长按了第%ld张图片", (showButton.tag - kPhotoTag));
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
if (!_deleteButton) {
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.tag = 5521 + (showButton.tag - kPhotoTag);
[deleteButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
deleteButton.backgroundColor = [UIColor whiteColor];
deleteButton.bounds = CGRectMake(0, 0, 20, 20);
[deleteButton addTarget:self action:@selector(deletePicture:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.frame = CGRectMake(showButton.frame.size.width - deleteButton.frame.size.width, 0, deleteButton.frame.size.width, deleteButton.frame.size.height);
[showButton addSubview:deleteButton];
_deleteButton = deleteButton;
}
}
// 删除图片
- (void)deletePicture:(UIButton *)button
{
NSLog(@"从imageName中删除了第%ld张图片",(button.tag - 5521));
// 从存放所有Image的数组里移除当前点击的Image
[self.imageNameArray removeObjectAtIndex:(button.tag - 5521)];
if ((_imageNameArray.count + 1) % 2 == 0) {
_rowNumber--;
[self.tableView reloadData];
} else {
[self.tableView reloadData];
}
[button removeFromSuperview];
button = nil;
[self removeDeleteButton];
}
- (void)removeDeleteButton {
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
}
#pragma mark - UIImagePickerController 代理方法 #pragma mark - UIImagePickerController 代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{ {
...@@ -520,6 +575,11 @@ ...@@ -520,6 +575,11 @@
cell.photoButton2.tag = 2201; cell.photoButton2.tag = 2201;
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
// 添加长按手势
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
return cell; return cell;
} else { } else {
...@@ -561,6 +621,13 @@ ...@@ -561,6 +621,13 @@
[cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
cell.photoButton2.tag = kPhotoTag + (indexPath.row - 3) * 2 + 1; cell.photoButton2.tag = kPhotoTag + (indexPath.row - 3) * 2 + 1;
// 添加长按手势
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
UILongPressGestureRecognizer *longGR2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton2 addGestureRecognizer:longGR2];
return cell; return cell;
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
@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) int rowNumber;
@property (nonatomic, strong) UIButton *deleteButton;
@end @end
...@@ -101,6 +102,7 @@ ...@@ -101,6 +102,7 @@
largeVC.index = sender.tag - kPhotoTag; largeVC.index = sender.tag - kPhotoTag;
largeVC.allImageArray = _imageNameArray; largeVC.allImageArray = _imageNameArray;
largeVC.pictureSaveMode = PictureLocalMode; largeVC.pictureSaveMode = PictureLocalMode;
[self removeDeleteButton];
[self.navigationController pushViewController:largeVC animated:YES]; [self.navigationController pushViewController:largeVC animated:YES];
...@@ -118,7 +120,7 @@ ...@@ -118,7 +120,7 @@
if (sender.tag == 2201) { if (sender.tag == 2201) {
_rowNumber++; _rowNumber++;
} }
[self removeDeleteButton];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"找不到相机" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"找不到相机" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show]; [alert show];
...@@ -130,6 +132,7 @@ ...@@ -130,6 +132,7 @@
picker.videoQuality = UIImagePickerControllerQualityTypeLow; picker.videoQuality = UIImagePickerControllerQualityTypeLow;
[self presentViewController:picker animated:YES completion:nil]; [self presentViewController:picker animated:YES completion:nil];
} }
} }
...@@ -214,6 +217,9 @@ ...@@ -214,6 +217,9 @@
cell.photoButton2.tag = 2201; cell.photoButton2.tag = 2201;
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
return cell; return cell;
} else { } else {
...@@ -255,12 +261,65 @@ ...@@ -255,12 +261,65 @@
[cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
cell.photoButton2.tag = kPhotoTag + (indexPath.row - 1) * 2 + 1; cell.photoButton2.tag = kPhotoTag + (indexPath.row - 1) * 2 + 1;
// 添加长按手势
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
UILongPressGestureRecognizer *longGR2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton2 addGestureRecognizer:longGR2];
return cell; return cell;
} }
} }
- (void)longClick:(UIGestureRecognizer *)longGR {
// 获取到点击的显示图片的按钮
UIButton *showButton = (UIButton *)longGR.view;
NSLog(@"我长按了第%ld张图片", (showButton.tag - kPhotoTag));
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
if (!_deleteButton) {
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.tag = 5521 + (showButton.tag - kPhotoTag);
[deleteButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
deleteButton.backgroundColor = [UIColor whiteColor];
deleteButton.bounds = CGRectMake(0, 0, 20, 20);
[deleteButton addTarget:self action:@selector(deletePicture:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.frame = CGRectMake(showButton.frame.size.width - deleteButton.frame.size.width, 0, deleteButton.frame.size.width, deleteButton.frame.size.height);
[showButton addSubview:deleteButton];
_deleteButton = deleteButton;
}
}
// 删除图片
- (void)deletePicture:(UIButton *)button
{
NSLog(@"从imageName中删除了第%ld张图片",(button.tag - 5521));
// 从存放所有Image的数组里移除当前点击的Image
[self.imageNameArray removeObjectAtIndex:(button.tag - 5521)];
if ((_imageNameArray.count + 1) % 2 == 0) {
_rowNumber--;
[self.tableView reloadData];
} else {
[self.tableView reloadData];
}
[button removeFromSuperview];
button = nil;
[self removeDeleteButton];
}
- (void)removeDeleteButton {
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
}
// section高度 // section高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
......
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