touchMoved函数中的图像ID

时间:2012-03-26 11:54:56

标签: iphone objective-c cocoa-touch

我目前正在处理Iphone应用程序中的手势

我使用了正常工作的触摸手势功能。

我的触摸手势功能正在处理图像(如拖动) 我想问一下是否有办法获取当前处于触摸手势功能的图像的id

touchMoved函数就是那样

- (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 个答案:

答案 0 :(得分:1)

检测您触摸的图像

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