1

私のhitViewがUIPanGestureRecognizerの後にスーパービューから部分的に来る場合、UILongPressGestureRecognizerは機能しません。なんで?

   - (id)initWithFrame:(CGRect)frame 
    {
      UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    [panGesture setMaximumNumberOfTouches:1];
    [panGesture setDelegate:self];
    [_glassesImage addGestureRecognizer:panGesture];


    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(enchance:)];
    longPressGesture.minimumPressDuration = 0.2;
    [_glassesImage addGestureRecognizer:longPressGesture];


    [self addSubview:_glassesImage];
    }



    - (void)enchance:(UILongPressGestureRecognizer *)gestureRecognizer 
   {
        UIView *hitView = [gestureRecognizer view];
        hitView.alpha=0.6;
        inLongPress=YES;
        gestureRecognizer.allowableMovement = 200;

      if ([gestureRecognizer state] == UIGestureRecognizerStateEnded){
        hitView.alpha=1.0;
        inLongPress=NO;

      }
    }
4

2 に答える 2

2

ジェスチャレコグナイザーのデリゲートを定義してから、次の実装を提供してください。

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

参照

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
 }
于 2012-07-02T08:51:24.660 に答える
0

longPressGestureにデリゲートを追加します。

longPressGesture.delegate = self;

お役に立てればと思います。

于 2012-07-02T09:02:53.817 に答える