views:

1055

answers:

5

I have an application with a view containing several subviews. The subviews did not implement any touchesbegins logic. The Superview implemented all touchesbegins logic and manipulated each subview respectively if it was touched (determined by hit testing).

I have since been converting my subviews to layers. My problem now is that if I touch a layer, the hosting view of the superlayer never gets the touchesbegins method called. However if I touch the background, the touchesbegin method fires.

I understood from documentation that layers cannot handle events, if this is so why would it block events to the hosting view?

Thanks for any help, can't get my head around this.

-Corey

+1  A: 

CALayers should not block touch events. Is your userInteractionEnabled flag set in the hosting view (sounds like it is, if you're getting SOME touches)? Is it inside a UIScrollView, which may be doing its own touch-handling.

Ben Gottlieb
Ben this I my first post here, I'm not sure if I am supposed to post my responses as answers or as a comment to your answer. Hopefully I did it right.
Corey Floyd
A: 

@Ben I am not using UIScrollView and my userInteractionEnabled flag is set

However, my touchesbegan method is NOT getting fired even with a background click as I previously stated. Instead my app crashes if I click the background and does nothing if I click on a sublayer.

I am getting an error concerning the CALayer Delegate. (The debugger crashes on the instruction CALayerGetDelegate).
I was under the assumption that the layer that Cocoa Touch attaches to all views automatically has its delegate set to the view it backs. However, even if I explicitly set the delegate, there is no change and I get the same crash.

I'm new to layers, I imagine I am missing something fundamental here.

Thanks again for the help

Corey Floyd
+1  A: 

I found the problem... I was releasing the sublayers I was creating using [CALayer layer]. Since I didn't have control of them, I shouldn't have been managing them.

Corey Floyd
A: 

What class is your touchesBegan method in? I was having a similiar problem because my touchesBegan method was in a UIView subclass. After moving the method to a UIViewController subclass, my problem was fixed.

Try doing that.

iPhoneGuy101
A: 

I am also getting issue of CALayerGetDelegate, this occurs, when I tried to release graph object of coreplot library.

Anyone else faced this issue and solved this issue?

Jignesh Brahmkhatri