So this is very, very weird. I've added a Swipe Gesture Recognizer from the starboards into the view for the first tab in my 6-tab tab bar. I set it to the left direction and connected it as an Action to the firstTabViewController.h. And it works perfectly.
Now, if I try to add the "right direction" Swipe Gesture recognizer to this first tab in the same way, the action doesn't even register.
Also, if I try to do the same thing in another one of the tabs (not the one at index 0), or move the working tab to a different position in the tab bar, the app crashes with a bad access error when I swipe.
firstTabViewController.h
- (IBAction)swipeLeft:(id)sender; // Works fine
- (IBAction)swipeRight:(id)sender; // Doesn't even register
firstTabViewController.m
- (IBAction)swipeLeft:(id)sender {
int nextIndex = CURRENT_INDEX + 1; // I did modify this accordingly when the tab was moved
[self.tabBarController setSelectedIndex:nextIndex];
NSLog(@"Swipe left");
}
- (IBAction)swipeRight:(id)sender {
NSLog(@"Swiped Right");
}
Just tested this and it works:
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
swipeLeft.delegate = self;
[swipeLeft release];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
swipeRight.delegate = self;
[swipeRight release];
-(void) swipeRight:(UISwipeGestureRecognizer *) recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
NSLog(@"swipe right");
}
-(void) swipeLeft:(UISwipeGestureRecognizer *) recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)
NSLog(@"swipe left");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.