I have a Background view (UIImageView) in that i am adding a view(UIView). this contentView(UIView) contains UIPanGestureRecognizer.
I am giving UIPanGestureRecognizer to contentView by bellow code :
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(movePhoto:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[contentView addGestureRecognizer:panRecognizer];
[panRecognizer release];
and then i am adding this contentView to Background View (UIImageView) by bellow code :
[imgBG addSubview:contentView]; // here imgBG is Background view.
but when i move this contentView it goes out of imgBG.
bellow is the method to move contentView
[[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}
translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];
CGFloat finalX = [sender view].center.x;
CGFloat finalY = [sender view].center.y;
[[sender view] setCenter:CGPointMake(finalX, finalY)];
I think, here the contentView should remain inside the imgBG as it is the subview of imgBG.
Please let me know whether there is a problem in my code or its due to UIPanGestureRecognizer.
thanks in advance.
I just had to do :
[imgBG setClipsToBounds:YES];