//添加手势
-(void)addSwipeGesture{
//左右滑动
self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
self.leftSwipeGestureRecognizer.delegate = self;
self.rightSwipeGestureRecognizer.delegate = self;
self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.contentView addGestureRecognizer:self.leftSwipeGestureRecognizer];
[self.contentView addGestureRecognizer:self.rightSwipeGestureRecognizer];
}
- (void)handleSwipes:(UISwipeGestureRecognizer *)sender{
if (self.titles.count==0) {
return;
}
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
if (self.currentIndex>=self.titles.count-1) {
return;
}
if (self.currentIndex<self.titles.count-1) {
self.currentIndex++;
}
self.pageTitleView.selectedIndex = self.currentIndex;
}
if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
if (self.currentIndex<=0) {
return;
}
if (self.currentIndex>0) {
self.currentIndex--;
}
self.pageTitleView.selectedIndex = self.currentIndex;
}
}