Understanding touch responder chain to UIView over OF View

Hi,

So I’ve got some UIViews running nicely on top of the main OF GL View… and actions created either programmatically e.g. Target-Action pairs:

  
[currentCell.sendButton addTarget:self action:@selector(sendButtonPressed:withEvent:) forControlEvents:UIControlEventTouchDown];  

or using nib files and IBAction methods all work fine.

What don’t work are the three standard iOS touch methods, neither in my UIViewController subclass nor in its UIView subclasses:

  
  
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event  
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  
  

I’m assuming that EAGLView.mm catches all of those touches, converts them to the OF equivalent of touchDown, touchMoved, touchUp… and the responder chain stops there.

So, now I have a UIView that’s covering about a quarter of the GLView - the GLView still gets the touch events, but the UIView gets no touch events in the view itself, only the above-mentioned target-action pairs.

Any way to get those UIResponder methods working in my UIView on top of the GLView?

Thanks for any tips!

hey Gwydion,

if you place UIViews over the top of your glView then they should be receiving touch events ok.
if anything, those UIViews will be stopping touches reaching the glView below.

touchDown, touchMoved, touchUp methods can only be extended in a UIView, not in the UIViewController.
are you extending your UIView touchDown, touchMoved, touchUp methods?
and how are you using this extended UIView?

L.

Hi Julapy,

Thanks for getting back to me. Yes, that’s what I was expecting too, that the view on top would still get the full touches.

More info:
I have a UIViewController which has a nib file containing a couple of UIViews: PortraitView and LandscapeView, hooked up from

  
@property (nonatomic,retain) UIView *portraitView;  
@property (nonatomic,retain) UIView *landscapeView;  

to the nib.

On top of that I have another set of small subviews, called LandscapeCell, which are UIView class. Even though this on top of the landscape view, it also doesn’t trigger its own touchesBegan. I tried changing this to UIControl class, but no difference.

Finally, there’s a popup that appears on top of a section of the LandscapeCells. That’s also a UIControl. It also gets no touchesBegan triggers.

Both the LandscapeCells and popup are within the bounds of the landscapeView underneath. On the screen I can see and touch 4 views: the main full-screen GLView, the quarter-screen landscapeView, the smaller LandscapeCells, and the even smaller pop-up. But only GLView responds to the OF touchDown etc.

I thought it might be due to the landscapeView having some transparency, but trying it with an opaque background colour makes no difference.

Also, regarding touchesBegan in a view controller. The examples I have seen have the touchesBegan method inside the view controller class, it just needs to refer to a specific view inside that method to do something meaningful, right?

e.g. this can be inside a view controller:

  
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
UITouch *touch = [touches anyObject];  
gestureStartPoint = [touch locationInView:self.view];  
...  

Maybe the clue is in the fact that the GLView still gets its touches…? But the uiviews target-actions still get triggered via touch… hmmm…

PS: just double-checked and User Interaction Enabled and Multiple Touch are enabled in all views…

Ok, got it! Was due to me changing UIViews to UIControls. Changing back to UIViews resulted in the touchesBegan methods being triggered again.

Thanks for your help Julapy - just asking some questions helped me think about it a bit more and debug further…

So… nothing to do with OF… just user error… :wink: