2
votes

enter image description here

Hi all,

I am having some issue with detecting touches. Please refer image where yellow and brown are my UIView which is subclassed to detect the transparent touches. I have added three gesture recognizers pan, tap and rotation on that UIViews, but when I subclass UIView and override the - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event method to detect all the Imageviews added, gesture recognizers stop working outside the ImageView. And if I am not using subclass then it's unable to detect touches for ImageView on the yellow UIView. I tried the solution from this link

Forwarding UIGesture to views behind

though it is not the same as my requirement, but it didn't help! Any help/hint is appreciated! Thanks in advance.

3
If you are trying to get touch/gesture on a UIImageView, you need to set its property userInteractionEnabled = YES.Amar
Amar, for both UIViews and ImageViews userInteractionEnable is set to YES.Minakshi
So you are trying to detect touches on the yellow UIView?Amar
I want to detect touches of both UIViews when user will touch respective images on it. This is achieved already by overriding pointInside, but now gestures are not responding for transparent area of UIView.Minakshi
Please post some code base..Shamsudheen TK

3 Answers

1
votes

I have resolved the issue myself. I achieved the my target by applying gesture recognizers on superview not separate for each uiimageview or the colored uiviews. I have added uiviews on superview and now gesture is getting applied to imageview also. And also changed the code in gesture actions so that gesture will get applied to touched imageview and not on superview.

0
votes

Try implementing gestureRecognizerShould begin in your subclass, test to see if the class of the recognizer is those classes [gestureRecognizer class] == [UITapGestureRecognizer class] for example, and return yes if it is.

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/gestureRecognizerShouldBegin:

0
votes

The only way I've found to fix this is to add your stack of views as children to a UIView (A). It should be the same size as your transparent view/ all of the child views on your stack. You should implement the gesture recogniser in the view controller if and connect (A) as the iboutlet (just drag and drop a gesture recogniser onto A in interface builder for example).

(View Controller)
 |->(A)
     |->(1) Need gesture 
     |->(2) Need another gesture
     |->(3) Transparent (messing everything up)

Connect the gesture handlers to the appropriate children of A who need to handle them.

For View Controller

@interface AUIViewController : UIViewController <bla, bla, UIGestureRecognizerDelegate >

For (1)

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{/*yada yada*/}

In my opinion, this is an apple bug.

My answer is pretty much this but it is a work around for what is in my opinion, a bug.

P.S, sorry I didn't fix this without using interface builder. Hope its still helpful