Noob working on an application that displays short texts selected at random from an array–a new text each time the user swipes. I was using “previous” and “next” buttons, and that was working fine. Then I added the swipes, and a right swipe (from left) produced “previous” and a left swipe (from right) produced “next”, but in both cases the animation was a right-to-left swipe. Then I got rid of the buttons entirely and both right and left swipes produced “next”–no way to get “previous”–and again only the right-to-left swipe animation.
Here’s the relevant code from viewDidLoad:
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextHaiku)];
swipeRight.numberOfTouchesRequired = 1;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextHaiku)];
swipeLeft.numberOfTouchesRequired = 1;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
Here’s the relevant code from the “next” method.
-(void)nextHaiku
{
<...a bunch of code setting up the UItextView 'haiku_text'...>
CATransition *transitionR = [CATransition animation];
transitionR.duration = 0.25;
transitionR.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transitionR.type = kCATransitionPush;
transitionR.subtype =kCATransitionFromRight;
transitionR.delegate = self;
[self.view.layer addAnimation:transitionR forKey:nil];
[self.view addSubview:self.haiku_text];
}
And likewise here’s the “previous” method.
-(void)previousHaiku
{
<...a bunch of code setting up the UITextView haiku_text...>
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromRight;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:self.haiku_text];
And here, just for the sake of thoroughness, is a pic of my connections:

Any thoughts about what I might be doing wrong?
In
viewDidLoadyou are using the same selectornextHaikyfor both recognizers when init. This overwrites the bindings you make in IBChange the appropriate
UISwipeGestureRecognizerinit to fix the problem