0

IUPanGesture に次のハンドラーを使用しています。ただし、パンが終了すると、移動中の UIView が消えます。このコードに他に何か追加する必要がありますか?

- (void)pan:(UIPanGestureRecognizer *)gesture
{
  if ((gesture.state == UIGestureRecognizerStateChanged) ||
  (gesture.state == UIGestureRecognizerStateEnded)) {

  CGPoint location = [gesture locationInView:[self superview]];

  [self setCenter:location];
  }
}
4

1 に答える 1

1

I don't know if it's documented anywhere, but I've found empirically that any gesture states other than UIGestureRecognizerStateBegan, UIGestureRecognizerStateChanged, and UIGestureRecognizerStateRecognized will have garbage touch and location information. In many cases, the code would even crash trying to access a non-existent touch.

So, changing the condition as follows should fix the issue you're having:

- (void)pan:(UIPanGestureRecognizer *)gesture
{
  if (gesture.state == UIGestureRecognizerStateChanged) {
    CGPoint location = [gesture locationInView:[self superview]];
    [self setCenter:location];
  }
}
于 2010-12-26T01:51:28.990 に答える