0

I need have a view where users can draw multiple rectangles. Now I need to be able to move those rectangles using a Pan gesture. The problem I am having is that I can move any single rectangle with the Pan gesture recognizer with no problem. Now when I use 2 fingers to Pan 2 rectangles to move simultaneously it doesn't work.

Seem to me that the problem is the target/action that I specified for the pan gesture gets fired only once.

My view adopts the UIGestureRecognizerDelegate and has defined this delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{   
    return YES;
}

Thanks in advance!

4

1 回答 1

1

通过制作方法将手势识别器分别添加到每个创建的矩形视图中。

像这样

- (void)addGestureRecognizersToPiece:(UIView *)piece
{
  // Add the gesture recognizer to the piece here
}

您可以循环将手势识别器同时添加到所有片段,或者在您创建每个矩形时,只需在创建矩形后触发此方法,并将其作为片段参数传递给此函数。

那应该有帮助。

于 2011-10-20T06:24:00.473 回答