0

I have an application in which i have to move images, problem is arising when mouse touches the images it gets moved but if it touches the main View, whole view is also moving.

I tried view.userInteractionEnabled=NO;

but after one move whole view gets freeze.

I want my view to be static(not moving)

Help !!!

here is the code

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {  
    UITouch *touch = [[event allTouches] anyObject];

    UIImageView *imgPimples = [[UIImageView alloc]init];
    imgPimples = (UIImageView*)[touch view];
    CGPoint touchLocation = [touch locationInView:imgPimples];
    imgPimples.center = touchLocation;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
4

2 回答 2

0
if ([touch.view isKindOfClass:[UIImageView class]]){
imgPimples.center = touchLocation;
}

assuming your parent view is not also a UIImageView.

于 2011-08-05T09:28:17.020 回答
0

Just check whether touched class is of kind UIImageView.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
    if ([[touch view] isKindOfClass:[UIImageView class]]) {
        UIImageView *imgPimple;
        imgPimple = (UIImageView *)[touch view]; 
        CGPoint touchLocation = [touch locationInView:imgPimple];
        imgPimple.center = touchLocation;
    }

}

I think it will serve your purpose.

于 2011-08-05T09:54:20.763 回答