Noob 正在开发一个应用程序,该应用程序显示从数组中随机选择的短文本——用户每次滑动时都会显示一个新文本。我使用的是“上一个”和“下一个”按钮,效果很好。然后我添加了滑动,向右滑动(从左侧)产生“上一个”,向左滑动(从右)产生“下一个”,但在这两种情况下,动画都是从右到左的滑动。然后我完全摆脱了按钮,左右滑动都产生了“下一个”——没有办法得到“上一个”——再次只有从右到左的滑动动画。
以下是来自的相关代码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];
这是“下一个”方法中的相关代码。
-(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];
}
同样,这里是“以前的”方法。
-(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];
在这里,只是为了彻底,是我的连接图片:
关于我可能做错了什么的任何想法?