UIPanGestureRecognizer prevent 2 views to overlap
I have 2 UIViews. When I move one view, I need it not to overlap the
second how do I do it?
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x +
translation.x,
recognizer.view.center.y +
translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
// Figure out where the user is trying to drag the view.
CGPoint centerOfMovingObject = CGPointMake(self.view.bounds.size.width
/ 2,
recognizer.view.center.y +
translation.y);
UIButton* otherButton = nil;
if (recognizer.view.tag == 1) {
otherButton = (UIButton*)[self.view viewWithTag:2];
}else{
otherButton = (UIButton*)[self.view viewWithTag:1];
}
// Figure out where the user is trying to drag the view.
CGPoint centerOfTheOtherObject =
CGPointMake(self.view.bounds.size.width / 2,
recognizer.view.center.y +
translation.y);
// **Prevent from overlaping**???
}
No comments:
Post a Comment