tableViewcell上进行手势的添加
2015-10-20 15:27
441 查看
未进行操作时是这样的:
轻扫或者点击之后为这样的:
轻扫或者点击之后为这样的:
self.isLeft = NO;//默认为左边按钮是不出现的状态 //编辑按钮 self.editButton = [[UIButton alloc] initWithFrame:CGRectMake(BOUNDS.size.width-46, 0, 46, 43)]; [_editButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; [_editButton addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:_editButton];
//删除按钮 self.deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(_editButton.frame.origin.x, 47, _editButton.frame.size.width, _editButton.frame.size.height)]; [_deleteBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; [_deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:_deleteBtn];
//向左轻扫 UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftRecognizerThisCell:)]; leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; [self.subView addGestureRecognizer:leftRecognizer]; //向右轻扫 UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightRecognizerThisCell:)]; rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight; [self.subView addGestureRecognizer:rightRecognizer]; //点击 UITapGestureRecognizer *pan = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognizerThisCell:)]; [self.subView addGestureRecognizer:pan];
//手势的触发 //向左轻扫时手势添加的这个view左移动 - (void)leftRecognizerThisCell:(UIGestureRecognizer *)gesture { UIView *view = gesture.view; [UIView animateWithDuration:0.2 animations:^{ view.frame = CGRectMake(-46, _subView.frame.origin.y, _subView.frame.size.width, _subView.frame.size.height); _isLeft = YES; }]; } //向右轻扫时手势添加的这个view右移动 - (void)rightRecognizerThisCell:(UIGestureRecognizer *)gesture { UIView *view = gesture.view; if (_isLeft) { [UIView animateWithDuration:0.2 animations:^{ view.frame = CGRectMake(0, 0, _subView.frame.size.width, _subView.frame.size.height); _isLeft = NO; }]; } } //点击时,先判断此时的状态 - (void)panRecognizerThisCell:(UIPanGestureRecognizer *)gesture { if (_isLeft) { [self rightRecognizerThisCell:gesture]; } else { [self leftRecognizerThisCell:gesture]; } }
相关文章推荐
- Objective-C categories in static library链接库真实链接的大小
- 批处理设置IP地址
- 表格
- hdu3068最长回文(manacher算法)
- idea intellij对Spring进行单元测试
- java继承中父类、子类的初始化过程
- markdown编辑器
- Customizing Qt Widgets Using Style Sheets
- MySql--查询某字段相同数据的条数据
- gdi软光栅化注意事项
- Paho
- 合肥周边适合户外烧烤地点
- 【集合类型的并发】Collections.synchronizedList 的使用
- Android C++中 sp<> wp<>知识
- 浏览器兼容性解决方法
- http网址链接图片的处理及显示
- iOS学习之sqlite的创建数据库,表,插入查看数据
- goaccess-nginx日志分析工具简介
- 了解Android中的接口回调机制
- Service启动方式之startService,及注意事项