我有UIPanGestureRecognizer
,我试图让它只向一个方向滑动(向上)。
我还没有找到一个有效的解决方案。谢谢。
这是我目前的代码:
- (void)panGesture:(UIPanGestureRecognizer *)recognizer{
CGPoint t = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + t.x, recognizer.view.center.y + t.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
答案 0 :(得分:1)
- (void)panGesture:(UIPanGestureRecognizer *)recognizer {
CGPoint t = [recognizer translationInView:self.view];
if (t.y < 0) {
t = CGPointMake(0, t.y);
}
else {
t = CGPointMake(0, 0); // look at this
}
recognizer.view.center = CGPointMake(recognizer.view.center.x + t.x,
recognizer.view.center.y + t.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
为了能够上下拖动,请使用CGPointMake(0, t.y);
而不是我的if