Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Alex Puray
1,304 PointsPan Gesture Screen Boundaries.
Hello, I have loaded the pan gesture programmatically with a Uiimage. How do I restrict that image within the boundaries of the screen? here the code I am currently using .
- (IBAction)didPan:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint translation = [panGestureRecognizer translationInView:_blue.superview];
_blue.center = CGPointMake(_blue.center.x + translation.x,_blue.center.y + translation.y);
[panGestureRecognizer setTranslation:CGPointZero inView:_blue.superview];
}
2 Answers
Sam Soffes
Treehouse Guest TeacherAlex,
Give your gesture recognizer a delegate. There's a method for should receive touch. You can just return YES or NO if the touch is in the frame you're looking for. Use CGRectContainsPoint to make the math easy :)
Alex Puray
1,304 PointsIs there anyway you could provide me with an example? Having a lot of trouble on this.