Disable toucesMoved on UIView
I have a UIImageView on which I am adding multiple UIImages on multiple click of a button and moving it with the help of TouchesMoevd. The problem is whenever I move the UIimage it moves through out the UIView.
I want my image to move only in UIImageView.
I know it is easy but I dont know how to restrict the image motion in particular portion???
help ...
here is my code og TouchesMoved Method.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:[imgPimple superview]];
imgPimple.clipsToBounds = YES;
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)ev开发者_Python百科ent
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
finally i have resolved this problem
solution is: this code in toucesMoved method
UITouch *touch = [[event allTouches] anyObject];
imgPimple = (UIImageView*)[touch view];
CGPoint touchLocation = [touch locationInView:[image superview]];
if (CGRectContainsPoint(CGRectMake(15, 20, 280, 220), touchLocation))
{
if ([touch.view isKindOfClass:[UIImageView class]])
{
imgPimple.center = touchLocation;
}
}
精彩评论