Search code examples
iphoneobjective-cuiviewuiviewcontrollertouchesmoved

Disable UIView on TouchesMoved


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
{
}

Solution

  • 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.