iOS手势识别器仅在用户触摸视图后启动

时间:2014-02-15 02:59:58

标签: ios iphone objective-c cocoa-touch uigesturerecognizer

我有一个UIPinchGestureRecognizer,我已添加到自定义UIView,随后将其添加为我的主视图的子视图。出于某种原因,当用户首次尝试捏合时,不会检测到捏合手势,但是对于任何后续尝试都会检测到捏合手势。请参阅下面的代码,用户必须在打印出nslog之前至少触摸一次视图,以便用户稍后进行操作。

声明:

        self.pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(expandAction:)];
        self.pinchGesture.scale = 0.0;
        self.pinchGesture.delegate = self;
        [self addGestureRecognizer:self.pinchGesture];

动作:

-(void)expandAction:(UIPinchGestureRecognizer *)sender {
    NSLog(@"pinch detected");
    //stop reminding user
    [self stopTimer:self.pinchExpandTimer];
    [UIView animateWithDuration: 0.0
                          delay: 0.0
                        options: UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionBeginFromCurrentState
                     animations: ^{
                         [self.pinchCircle1 removeFromSuperview];
                         [self.pinchCircle2 removeFromSuperview];
                     }
                     completion: ^(BOOL finished){
                     }];
    //calculate progress
    CGFloat progress = MIN(sender.scale/5, 1.0);
    [self setPinchAnimationWithProgress:progress];
 }

代表:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark UIGestureRecognizer Delegate

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return YES;
}

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

基本上,感觉用户必须“选择”视图然后执行手势以便拾取它。我已经尝试在视图上启用用户交互和/或设置第一响应者但它仍然无效。如果有任何效果,在此视图中还有其他手势识别器正在使用,但我认为不应该这样做。有没有人有任何想法?

1 个答案:

答案 0 :(得分:0)

固定。问题是我在初始化之后就在我的UIPinchGestureRecognizer上设置了scale属性。这可能是Apple代码中的一个错误。