Id of Image in touchMoved Function

2020-06-29 10:52发布

问题:

I m a currently working on gestures in an Iphone application

i used the touch gesture function which are working properly.

my touch gesture functions are working on an Image (Like Dragging) i want to ask is there a way to get the id of that image which is currently in touch gesture function

the touchMoved Function is like that

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    // Calculate and store offset, and pop view into front if needed
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [[self superview] bringSubviewToFront:self];
}
// During movement, update the transform to match the touches
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{

    // Calculate offset
    CGPoint pt = [[touches anyObject] locationInView:self];
    float dx = pt.x - startLocation.x;
    float dy = pt.y - startLocation.y;
    CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);


    // Remove Image (set Cordinated out of View)
    if ((newcenter.x <= 9) || (newcenter.y >= 403)) {
       //NSLog(@"Delete Image");
       newcenter.x = 1000;
        newcenter.y = 1000;

 }


     self.center = newcenter;
    //    
}

回答1:

To detect your touched imageView

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    if([[touch valueForKey:@"view"] tag] > 0)
    {
        yourImageView=[touch valueForKey:@"view"]; //here's the magic :)
    }
}