2013-03-17 52 views
0

所以在这里我有一个循环,使用一个数组在屏幕上创建一堆不同的方块,并且我添加了一个手势识别器来检测平底锅。事情是,我希望能够平滑地将一个物体滑到下一个物体上,而不会抬起我的手指。但是,用我现在的代码,我必须提起手指并单独滑过每个对象。有谁知道如何制作它,以便我可以平滑地将手指滑过每个物体,并让它们在滑过时执行其功能?这里是我的代码:检测多个对象的平移?

int numby = [squareLocations count]; 

    for (int i = 0; i < numby; i++) 
    { 
     NSValue *pointLocation = [squareLocations objectAtIndex:i]; 
     CGPoint tmpPoint = [pointLocation CGPointValue]; 
     UIImage *theSquare = [UIImage imageNamed:@"square.png"]; 

     UIButton *squareButton = [[UIButton alloc] init]; 

     squareButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
     squareButton.frame = CGRectMake(tmpPoint.x, tmpPoint.y, theSquare.size.width, theSquare.size.height); 
     squareButton.tag = *(&i); 
     [squareButton setImage:theSquare forState:UIControlStateNormal]; 

     UIPanGestureRecognizer *slide = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; 
     [squareButton addGestureRecognizer:slide]; 

     [whereStuffActuallyHappens addSubview:squareButton]; 

    } 

} 

- (void) handlePan:(UIPanGestureRecognizer *)slide { 


    [slide setTranslation:CGPointZero inView:slide.view]; 

    NSInteger tag = slide.view.tag; 
    NSLog(@"Tag is: %i", tag); 

    [slide.view removeFromSuperview]; 
} 

回答

0

一个有点劈上下的方式做,这将是泛手势添加到您的方块,而不是上海华,检查哪一个具有手势它的框架发生碰撞的位置。

+0

有没有办法使用touchesBegin检查正方形的标签?我在想,如果我可以使用它来检查广场的标签,我可以这样做吗? – 2013-03-17 05:41:11

+0

我从来没有成功获得触摸开始工作,所以我可能是错的,但我不认为如果手指仍然在屏幕上,只是越过视图,它会被调用。 – Jsdodgers 2013-03-17 05:53:08

+0

如果我将pan识别器塞入touchesbegin会怎么样? – 2013-03-17 06:44:57