Situation: You need to find which layer the user touched.
Problem: Apple says that we should use [CALayer presentationLayer] to perform impact testing so that it displays what is actually on the screen at that time (it captures mid-animation information, etc.).
... except: presentationLayer does NOT return the original layers, it returns copies of it ... like this: hitTest will return a new CALayer instance that is not equivalent to the original.
How to find which actual CALayer was hit?
eg.
CALayer* x = [CALayer layer]; CALayer* y = [CALayer layer]; [self.view.layer addSublayer: x]; [self.view.layer addSublayer: y]; ... CALayer* touchedLayer = [self.view.layer.presentationLayer hitTest:touchPoint];
... but touched Layer "x", or is it "y"?
if( touchedLayer == x )
source share