0

在我的代码中,我有一个区域,当用户点击并按住时,UILongPressGestureRecognizer 会导致动画运行,并在动画结束时调用一个方法。(它基本上是在一个包含一个 CGPoint 的小区域正方形上长按,以便它开始长按动画,当它完成时,该点被删除。)

问题:在 iPhone 5s、SE 和 6 上,UILongPressGestureRecognizer 工作正常,但在之后发布的任何设备上,它都会很快被关闭,我已经在至少 11 种不同的设备上尝试过。这是为什么?!我很感激任何帮助。

-(void)prepareLongPressGesture{
_longGesture = [[UILongPressGestureRecognizer alloc]
      initWithTarget:self
              action:@selector(handleLongGesture:)];
  _longGesture.delegate = self;
  _longGesture.allowableMovement = self.frame.size.width*0.15;
  _longGesture.minimumPressDuration = 1.0;
  [self addGestureRecognizer:_longGesture];
}

- (void)handleLongGesture:(UILongPressGestureRecognizer*)gesture {
  switch (gesture.state) {
    case UIGestureRecognizerStateBegan:
      [self removeModifiablePoint];
      break;
    case UIGestureRecognizerStateChanged:
    case UIGestureRecognizerStateEnded:
    case UIGestureRecognizerStateCancelled: {
      if (self.animatedView.superview) {
        [self.animatedView removeFromSuperview];
      }
    } break;

    default:
      break;
  }
}

- (void)removeModifiablePoint {
    CGFloat sizeOFLongPressAnimation = 0.0;

    if (IS_IPAD) {
        sizeOFLongPressAnimation = 0.15*self.frame.size.width;
    }else{
        sizeOFLongPressAnimation = 0.27*self.frame.size.width;
    }

  if (!_animatedView) {
      self.animatedView =
      [[UIView alloc] initWithFrame:CGRectMake(0, 0, sizeOFLongPressAnimation, sizeOFLongPressAnimation)];


    self.animatedView.alpha = 0.7f;
    self.animatedView.layer.borderColor = [UIColor redColor].CGColor;
    self.animatedView.layer.borderWidth = 3.f;
    self.animatedView.layer.cornerRadius = sizeOFLongPressAnimation / 2.0f;

    self.progressView = [[UIView alloc] initWithFrame:self.animatedView.bounds];
    self.progressView.backgroundColor = [UIColor redColor];
    self.progressView.layer.cornerRadius = sizeOFLongPressAnimation / 2.0f;

    [self.animatedView addSubview:self.progressView];
  }

  CGPoint center = [self.modifiablePointsArray[_modifiablePointIndex] CGPointValue];
  self.animatedView.center = center;
  [self addSubview:self.animatedView];
  self.progressView.transform =
      CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1f);

  [UIView animateWithDuration:2.f animations:^{
        self.progressView.transform = CGAffineTransformIdentity;
      }completion:^(BOOL finished) {
        if (finished) {
          [self.animatedView removeFromSuperview];
          [self.modifiablePointsArray removeObjectAtIndex:_modifiablePointIndex];
          [self setNeedsDisplay];
        }
   }];
}
4

0 回答 0