2013-03-20 94 views
1

我有MyCustomView視圖作爲UIControl類的子類。 我在我的視圖中繪製這樣的東西:檢測底層元素的觸摸

CAShapeLayer *line = [CAShapeLayer layer]; 
    .... 
    [self.layer addSublayer:line]; 

是無論如何它來檢測「線」接觸,並做一些工作?例如移動'線'。

+0

點擊這裏:http://stackoverflow.com/questions/3469211/is-it-possible-to-use-cocoa-touch-gesture-recognizers-with-layers-calayer-obje – Petar 2013-03-20 13:59:58

回答

1

你可以嘗試添加gesturerecognizers到您的UIView,然後調用

- (CALayer *)hitTest:(CGPoint)thePoint 

視圖的層上找到你打哪一層,例如;

CALayer* layerThatWasTapped = [line.layer hitTest:[gestureRecognizer locationInView:line]];