Commit 54200797 authored by admin's avatar admin

长按删除照片

parent e639546a
No preview for this file type
......@@ -33,6 +33,9 @@
@property (nonatomic, assign) int rowNumber;
@property (nonatomic, strong) NSLayoutConstraint *tableBottom;
@property (nonatomic, strong) NSLayoutConstraint *tableTop;
@property (nonatomic, strong) UIButton *deleteButton;
@end
@implementation LookOnLineDetailViewController
......@@ -160,6 +163,10 @@
lager.index = sender.tag - 1118;
lager.pictureSaveMode = PictureLocalMode;
lager.allImageArray = _imageNameArray;
[self removeDeleteButton];
[self.navigationController pushViewController:lager animated:YES];
}
......@@ -322,9 +329,9 @@
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
// [cell.photoButton1 addGestureRecognizer:longGR];
// cell.contentView.backgroundColor = [UIColor orangeColor];
// 添加长按手势
UILongPressGestureRecognizer *longGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR];
return cell;
} else {
......@@ -365,11 +372,12 @@
[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:)];
//
// [cell.photoButton1 addGestureRecognizer:longGR];
// [cell.photoButton2 addGestureRecognizer:longGR];
UILongPressGestureRecognizer *longGR2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton2 addGestureRecognizer:longGR2];
return cell;
}
......@@ -377,27 +385,34 @@
}
- (void)longClick:(UIGestureRecognizer *)longGR
{
if (longGR.state == UIGestureRecognizerStateBegan) {
// 获取到点击的显示图片的按钮
UIButton *showButton = (UIButton *)longGR.view;
// 创建长按删除的按钮
- (void)longClick:(UIGestureRecognizer *)longGR {
// 获取到点击的显示图片的按钮
UIButton *showButton = (UIButton *)longGR.view;
NSLog(@"我长按了第%ld张图片", (showButton.tag - 1118));
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
if (!_deleteButton) {
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
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 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)];
......@@ -407,7 +422,18 @@
} else {
[self.tableView reloadData];
}
[button removeFromSuperview];
button = nil;
[self removeDeleteButton];
}
- (void)removeDeleteButton {
if (_deleteButton) {
[_deleteButton removeFromSuperview];
_deleteButton = nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
......
......@@ -58,6 +58,9 @@
@property (nonatomic) BOOL isComplete;
@property (nonatomic) BOOL isLoad;
@property (nonatomic, strong) NSMutableDictionary *groupUuidDict;
@property (nonatomic, strong) UIButton *deleteButton;
@end
@implementation AddQuestionViewController
......@@ -193,6 +196,7 @@
lager.index = sender.tag - kPhotoTag;
lager.pictureSaveMode = PictureLocalMode;
lager.allImageArray = _imageNameArray;
[self removeDeleteButton];
[self.navigationController pushViewController:lager animated:YES];
// CheckPicViewController *checkVC = [[CheckPicViewController alloc] init];
......@@ -216,7 +220,7 @@
_selectActionSheet.delegate = self;
_selectActionSheet.tag = 999283;
[_selectActionSheet showInView:self.view];
[self removeDeleteButton];
if (sender.tag == 2201) {
_rowNumber++;
......@@ -238,6 +242,57 @@
[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 代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
......@@ -520,6 +575,11 @@
cell.photoButton2.tag = 2201;
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// 添加长按手势
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
return cell;
} else {
......@@ -561,6 +621,13 @@
[cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
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;
}
......
......@@ -36,6 +36,7 @@
@property (nonatomic, strong) NSLayoutConstraint *tableBottom;
@property (nonatomic, strong) NSLayoutConstraint *tableTop;
@property (nonatomic, assign) int rowNumber;
@property (nonatomic, strong) UIButton *deleteButton;
@end
......@@ -101,6 +102,7 @@
largeVC.index = sender.tag - kPhotoTag;
largeVC.allImageArray = _imageNameArray;
largeVC.pictureSaveMode = PictureLocalMode;
[self removeDeleteButton];
[self.navigationController pushViewController:largeVC animated:YES];
......@@ -118,7 +120,7 @@
if (sender.tag == 2201) {
_rowNumber++;
}
[self removeDeleteButton];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"找不到相机" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
......@@ -130,6 +132,7 @@
picker.videoQuality = UIImagePickerControllerQualityTypeLow;
[self presentViewController:picker animated:YES completion:nil];
}
}
......@@ -214,6 +217,9 @@
cell.photoButton2.tag = 2201;
[cell.photoButton2 addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *longGR1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
[cell.photoButton1 addGestureRecognizer:longGR1];
return cell;
} else {
......@@ -255,12 +261,65 @@
[cell.photoButton2 addTarget:self action:@selector(showPicture:) forControlEvents:UIControlEventTouchUpInside];
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;
}
}
- (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高度
- (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