how to bound uiimagegview moving in particular portion
I am working on an application in which I am adding the same image again and again on a button click on random positions and moving those images.
But on moving those images, images can move in whole view inspite of moving in UIView i want my image to move only in subview(UIImage view) on which i am adding it.
here is my code of TouchesMoved
- (voi开发者_C百科d)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
UIImageView *imgPimple;// = [[UIImageView alloc]init];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:imgPimple superview];
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
What you should be doing is:
CGPoint touchLocation = [touch locationInView:[imgPimple superview]];
I think.
It seems to me that if you're deciding where to move it in its superview, and you get the touch location in the imgPimple view, it will behave incorrectly.
精彩评论