我有一个UIView对象,可以使用UIPanGestureRecognizer拖动它,但是我只希望它能够向上移动屏幕3/4。我不想被裁剪,但是要达到某个点并且不能被进一步拖动。到目前为止,我只允许它在Y轴上移动(这是需要的)。
- (IBAction)panGesture:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
谢谢你的帮助。
最佳答案
因此,只需检查新的Y坐标是否太小。如果视图太小,请不要更改视图:
- (IBAction)panGesture:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
CGPoint center = recognizer.view.center;
center.y += translation.y;
if (center.y < self.yMin)
return;
recognizer.view.center = center;
}
关于ios - 限制UIPanGesture识别器移动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9169949/