泛手势后UIView消失

时间:2010-12-26 01:45:49

标签: ipad uigesturerecognizer

我正在为IUPanGesture使用以下处理程序。但是当平底锅结束时,它正在移动的UIView消失了。我是否需要在此代码中添加任何其他内容?

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

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

  [self setCenter:location];
  }
}

1 个答案:

答案 0 :(得分:1)

我不知道它是否记录在任何地方,但我从经验上发现除了UIGestureRecognizerStateBeganUIGestureRecognizerStateChangedUIGestureRecognizerStateRecognized以外的任何手势状态都会有垃圾触摸和位置信息。在许多情况下,代码甚至会在尝试访问不存在的触摸时崩溃。

因此,如下更改条件应该可以解决您遇到的问题:

- (void)pan:(UIPanGestureRecognizer *)gesture
{
  if (gesture.state == UIGestureRecognizerStateChanged) {
    CGPoint location = [gesture locationInView:[self superview]];
    [self setCenter:location];
  }
}