IOS7 Tableviewcell滑动使用多菜单

////  DogTableViewCell.h//  doctor////  Created by 杨玉婷 on 15/11/3.//  Copyright © 2015年 chenzhen. All rights reserved.//#import@interface DogTableViewCell : UITableViewCell

{

UIPanGestureRecognizer *panRecognizer;

BOOL isLeft;

}

@property(nonatomic,assign)CGPoint panStartPoint;

@property(nonatomic,strong)UIButton *btn_Change;

@property(nonatomic,strong)UIButton *btn_Delete;

@property(nonatomic,strong)UIView *containerView;

@property(nonatomic,strong)UISwipeGestureRecognizer *leftSwipeGestureRecognizer;

@property(nonatomic,strong)UISwipeGestureRecognizer *rightSwipeGestureRecognizer;

@end






//

//  DogTableViewCell.m

//  doctor

//

//  Created by 杨玉婷 on 15/11/3.

//  Copyright © 2015年 chenzhen. All rights reserved.

//

#import "DogTableViewCell.h"

#import "UIViewExt.h"

@implementation DogTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

isLeft = NO;

[self.contentView addSubview:self.btn_Change];

[self.contentView addSubview:self.btn_Delete];

[self.contentView addSubview:self.containerView];

}

return self;

}

-(UIButton *)btn_Delete{

if (!_btn_Delete) {

_btn_Delete = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 44, 0, 44, 44)];

_btn_Delete.backgroundColor = [UIColor redColor];

[_btn_Delete setTitle:@"删除" forState:UIControlStateNormal];

[_btn_Delete addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];

}

return _btn_Delete;

}

-(UIButton *)btn_Change{

if (!_btn_Change) {

_btn_Change = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 44 * 2, 0, 44, 44)];

_btn_Change.backgroundColor = [UIColor grayColor];

[_btn_Change setTitle:@"修改" forState:UIControlStateNormal];

[_btn_Change addTarget:self action:@selector(changeClick) forControlEvents:UIControlEventTouchUpInside];

}

return _btn_Change;

}

-(void)deleteClick{

NSLog(@"删除");

}

-(void)changeClick{

NSLog(@"修改");

}

-(UIView *)containerView{

if (!_containerView) {

_containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];

_containerView.backgroundColor = [UIColor blueColor];

self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];

self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];

self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;

self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;

[_containerView addGestureRecognizer:self.leftSwipeGestureRecognizer];

[_containerView addGestureRecognizer:self.rightSwipeGestureRecognizer];

}

return _containerView;

}

- (void)handleSwipes:(UISwipeGestureRecognizer *)sender

{

if (sender.direction == UISwipeGestureRecognizerDirectionLeft && !isLeft) {

[UIView animateWithDuration:0.1 animations:^{

CGPoint viewPosition = CGPointMake(self.containerView.frame.origin.x - 44*2, self.containerView.frame.origin.y);

self.containerView.frame = CGRectMake( viewPosition.x , viewPosition.y , self.containerView.frame.size.width, self.containerView.frame.size.height);

}];

NSLog(@"尼玛的, 你在往左边跑啊....");

isLeft = !isLeft;

}

if (sender.direction == UISwipeGestureRecognizerDirectionRight &&isLeft) {

[UIView animateWithDuration:0.1 animations:^{

CGPoint viewPosition = CGPointMake(0, self.containerView.frame.origin.y);

self.containerView.frame = CGRectMake( viewPosition.x , viewPosition.y , self.containerView.frame.size.width, self.containerView.frame.size.height);

}];

NSLog( @"尼玛的, 你在往右边跑啊....");

isLeft = !isLeft;

}

}

- (void)awakeFromNib {

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end

你可能感兴趣的:(IOS7 Tableviewcell滑动使用多菜单)