在我的代码中,我有一个区域,当用户点击并保持时,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];
}
}];
}