I was working on a Cocoa Touch application, and trying to handle touches by determining which sublayer of a view's layer was touched. My controller's code looked like this:
CALayer *hitLayer = [self.view.layer hitTest:point];
This wasn't working. It would work if I tapped at the bottoms of sublayers, but not at the tops. After an hour of hair-pulling and Googling, I finally figured out that it works if one uses the presentation layer to do the hit-testing instead of the layer itself:
CALayer *hitLayer = [self.view.layer.presentationLayer hitTest:point];
So, I've solved my problem, but my question is: Why?
I've read through the Core Animation guide, and I understand that the presentation tree and rendering tree can differ from the object-model tree. But I don't understand why the presentation tree would (apparently) have different hit-testing behavior. Wouldn't the presentation tree and object-model have the same frames, bounds, etc.?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…