嗨,我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];
}
我的项目中有两个视图,一个是父视图(红色视图),另一个是子视图(绿色视图)。我的要求是我需要在父视图中平移子视图。我的handlePan
方法工作正常,但唯一的问题是它允许平移超出左侧的限制。它在右侧工作得很好。我需要更改代码请帮助我。