[英]How to limit area when sliding a view with UIPanGestureRecognizer?
I have setup a pan gesture to the slide view, I want to prevent the view sliding if it has been slid out. 我已经为幻灯片视图设置了平移手势,如果它已经滑出,我想防止视图滑动。 So I add this when I check UIGestureRecognizerStateChanged
所以我在检查UIGestureRecognizerStateChanged
时添加了它
CGPoint velocity = [(UIPanGestureRecognizer *)sender velocityInView:self.view];
if (sender.state == UIGestureRecognizerStateChanged) {
CGPoint velocity = [(UIPanGestureRecognizer *)sender velocityInView:self.view];
if (self.slideMenuView.frame.origin.x > 0 && velocity > 0) {
return;
}
// ...
}
It seems working, but if I slide the view to left then drag it to the opposite direction very quickly, the check will become invalid: 看来可行,但是如果我将视图向左滑动然后迅速将其向相反的方向拖动,则检查将变为无效:
Please help me out. 请帮帮我。
UPDATE: I have uploaded the project to GitHub: Vayn/ice 更新:我已将项目上传到GitHub: Vayn / ice
Can you try it. 你可以试试看吗?
if (self.view.frame.origin.x > 0) {
sender.view.frame = CGRectMake(0, sender.view.frame.origin.y,
sender.view.frame.size.width, sender.view.frame.size.height);
return;
}
I'm not sure. 我不确定。 I downloaded your project. 我下载了您的项目。 But can't build 但无法建立
library not found for -lSDCycleScrollView -lSDCycleScrollView找不到库
With help from @PhilCai1993 , we found solution for this problem finally: 在@ PhilCai1993的帮助下 ,我们终于找到了解决此问题的方法:
if (sender.state == UIGestureRecognizerStateChanged) {
// ...
// Add the check at the end of the block
if (sender.view.frame.origin.x >= 0) {
sender.view.frame = CGRectMake(0, sender.view.frame.origin.y,
sender.view.frame.size.width, sender.view.frame.size.height);
}
}
Just checking the position of slide menu view at the end of the block after updating the frame of slide menu view. 在更新幻灯片菜单视图的框架后,只需检查块末尾的幻灯片菜单视图的位置即可。
Thanks @anhtu for helping me solve this problem! 感谢@anhtu帮助我解决了这个问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.