0

So here I have a loop that creates a bunch of different squares on the screen, using an array, and I've added a gesture recognizer to detect for a pan. The thing is, I want to be able to smoothly slide over one object to the next, without lifting my finger. But, with my current code I have to lift my finger and slide over each object individually. Does anyone know how to make it so that I can smoothly slide my finger over each object, and have them perform their functions when they've been slid over? Here's my code:

    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];
}
4

1 回答 1

0

一种有点hack-ish的方法是将平移手势添加到正方形的超级视图中,并检查哪个手势的位置与其框架发生碰撞。

于 2013-03-17T05:28:55.290 回答