1.
@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer;
2.
@synthesize leftSwipeGestureRecognizer,rightSwipeGestureRecognizer;
3. 在视图控制器里加载这两个手势
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;
[self.viewaddGestureRecognizer:self.leftSwipeGestureRecognizer];
[self.viewaddGestureRecognizer:self.rightSwipeGestureRecognizer];
4.
- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//添加要响应的方法
}
if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
//添加要响应的方法
}
}