I'm using pangesturerecognizer to move objects around the screen.
How would I create a boundary for the object to not go past a certain point at the top of the screen?
I'm thinking of using this imageView.frame.origin.y > 0
but really unsure how to add it to this code.
The Status Bar is apparently covers 44pixels at the top of the screen and I'd proabaly like to do that to create a boundary of 44 at the bottom of the screen.
I'm using this code to do so:
- (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];
}
@SomeGuy Ok I tried to use :
recognizer.view.center = CGPointMake(MIN(recognizer.view.superview.frame.size.width - recognizer.view.frame.size.width / 2, MAX(-recognizer.view.frame.size.width / 2, recognizer.view.center.x + translation.x)),
MIN(recognizer.view.superview.frame.size.height - recognizer.view.frame.size.height / 2, MAX(-recognizer.view.frame.size.height / 2, recognizer.view.center.y + translation.y)));
But I could not figure ou the logic to get it to stop from going under the bar. I did though get it to stop by doing this.
EDIT
this code stops it from going under the top bar but I'm not sure how to create a border or stop it from going to far below.
if (recognizer.view.center.y < 44) {
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x ,
44 + translation.y );
}
else
{
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x ,
recognizer.view.center.y + translation.y );
}