0

I'm using a subclass of UIGestureRecognizer taken from here: Tap pressure strength detection using accelerometer

I'm adding it to two UIImageViews like so:

CPBPressureTouchGestureRecognizer *tap = [[CPBPressureTouchGestureRecognizer alloc] initWithTarget:self action:@selector(tapRegistered)];

[image1 addGestureRecognizer:tap];
[image2 addGestureRecognizer:tap];

For some reason, only the last UIImageView actually has the gesture recognizer added to it. Any ideas?

Thanks!

Community
  • 1
  • 1
codeman
  • 8,868
  • 13
  • 50
  • 79

2 Answers2

2

a UIGestureRecognizer can only be added to one view (it stores only one instance variable of view). so try creating two recognizers.

Mike K
  • 2,227
  • 1
  • 12
  • 6
  • I also tried adding it to UIButtons instead of UIImageviews...still only works on one of them. I think it has to do with the code from the link I posted above. Any help? – codeman Dec 27 '11 at 01:19
  • 1
    Make sure you have set userInteractionEnabled to YES on the views in addition to creating one UIGestureRecognizer object per view. If that doesn't work, some view probably overlaps the one you are tapping on. Set the background color of each view to a unique color so you can see their frames visually. – EricS Dec 27 '11 at 01:20
  • Still didn't work. Is it because the UIImageViews are both inside the same UIView? – codeman Dec 27 '11 at 01:28
0

There can be only one view for a given recognizer.

Nico
  • 3,826
  • 1
  • 21
  • 31