views:

36

answers:

2

HI . i am trying to move an UIImageView object with UITouch and have problem with the code how can i implement UITouch to detect only my UIImageView object ?

**imageA it my UIImageView

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

        UITouch *toucheA = [[event allTouches] anyObject];

    if ([toucheA view] == imageA) {
        CGPoint location = [toucheA locationInView:self];
        imageA.center = location;       

    }
}

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

    [self touchesBegan:touches withEvent:event];
    CGPoint postion = imageA.center;
    imageA.center = postion;
    postion.y = 230;
    imageA.center = postion;

}

but doesn't work !

+1  A: 

I think you can make a custom UIImageView by subclassing and receive touch event you want inside the custom view.

Generally, the top most view will receiver the touch event. If the view process the touch event and doesn't pass the event to another view, then the others view behind it are impossible to receive any touch event. If the view cannot deal with the touch event, it will pass that by calling super's method.

Toro
+1  A: 

http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html

You have a button there "Download sample code"

You should be fine after checking it out.

Also, Toro's advice is good also.

Cheers

lupu1001