【发布时间】:2013-09-06 00:57:57
【问题描述】:
我有一个CALayer,它的 hitTesting 工作正常。代码是这样的:
- (void)setup
{
_maskLayer = [CAShapeLayer layer];
_maskLayer.fillColor = [UIColor whiteColor].CGColor;
_maskLayer.path = somePath;
_theLayer.frame = CGRectMake(0, 0, size.width, size.height);
// Taps work fine if we do not apply the mask
// _theLayer.mask = _maskLayer;
}
- (IBAction)tapOnView:(UITapGestureRecognizer *)sender
{
CGPoint point = [sender locationInView:theView];
CALayer *subLayer = [_theLayer.presentationLayer hitTest:point].modelLayer;
if (subLayer != _theLayer && subLayer != nil) {
// Do something with the sublayer which the user touched
}
}
问题是,如果我取消注释带有mask 的行,我的命中测试总是返回nil。为什么面罩会杀命中测试?它在视觉上看起来是正确的。
【问题讨论】: