[英]how to limit UIPanGestureRecognizer with in parent view
Hi i have used UIPanGestureRecognizer
in my project. 嗨,我在我的项目中使用了
UIPanGestureRecognizer
。 i used below code to handle UIPanGestureRecognizer
我用下面的代码来处理
UIPanGestureRecognizer
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self];
CGFloat newX = MIN(recognizer.view.frame.origin.x + translation.x, self.frame.size.width - recognizer.view.frame.size.width);
CGRect newFrame = CGRectMake( newX,recognizer.view.frame.origin.y, recognizer.view.frame.size.width, recognizer.view.frame.size.height);
recognizer.view.frame = newFrame;
[recognizer setTranslation:CGPointZero inView:self];
}
i have two views in my project one is parent view(Red color view) and another one is child view (Green color view). 我在项目中有两个视图,一个是父视图(红色视图),另一个是子视图(绿色视图)。 My requirement is i need to pan the child view with in parent view.
我的要求是我需要在父视图中平移子视图。 My
handlePan
method working fine but the only problem is its allowing to pan beyond the limit in left side. 我的
handlePan
方法可以正常工作,但唯一的问题是它允许平移超出左侧的限制。 its working perfectly in right side. 它在右侧完美工作。 what i need to change in code Please help me out.
我需要更改代码的内容请帮帮我。
You should check UIGestureRecognizerDelegate 您应该检查UIGestureRecognizerDelegate
implement - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
and return NO when you don't want the gesture recognizer receive the touch event. 实现
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
并在您不希望手势识别器接收到触摸事件时返回NO。
This method is called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch.
在手势识别器上为新触摸调用touchesBegan:withEvent:之前,将调用此方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.