So Im making a page with pageControl (it's a page with multiple views with dots indicating which page you're in), my code looks like the following in viewDidLoad
:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
UIView *temp = [[UIView alloc]initWithFrame:self.view.frame];
temp.backgroundColor = [UIColor clearColor];
[temp addGestureRecognizer:swipe];
[self.view addSubview:temp];
And in the swipeAction selector I have:
- (void)swipeAction: (UISwipeGestureRecognizer *)sender{
NSLog(@"Swipe action called");
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//Do Something
}
else if (sender.direction == UISwipeGestureRecognizerDirectionRight){
//Do Something Else
}
}
To my surprise, this method only works when you swipe to the right (i.e. the else if
block gets called). When you swipe left, the swipeAction
doesn't even get called! This is strange, why does this happen and how should I change my code? Any reply is appreciated. Thanks a lot!
UIView
– Joanniejoao