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];
在这里,只是为了彻底,是我的关系的照片:
关于我可能做错什么的任何想法?
答案 0 :(得分:3)
在viewDidLoad
中,您在init时为两个识别器使用相同的选择器nextHaiky
。这会覆盖您在IB中的绑定
更改相应的UISwipeGestureRecognizer
初始化以解决问题