美文网首页
判断是否点击了某个图层

判断是否点击了某个图层

作者: 綪天de汰陽 | 来源:发表于2019-04-24 23:35 被阅读0次

/** Hit testing methods. **/

/* Returns the farthest descendant of the layer containing point 'p'.
 * Siblings are searched in top-to-bottom order. 'p' is defined to be
 * in the coordinate space of the receiver's nearest ancestor that
 * isn't a CATransformLayer (transform layers don't have a 2D
 * coordinate space in which the point could be specified). */

- (nullable __kindof CALayer *)hitTest:(CGPoint)p;

/* Returns true if the bounds of the layer contains point 'p'. */

- (BOOL)containsPoint:(CGPoint)p;

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
    CALayer *layer = [self.view.layer hitTest:touchPoint];
    
    //点击了图层(有可能为nil)
    NSLog(@"%@",layer);
}
屏幕快照 2019-04-24 下午11.34.43.png
屏幕快照 2019-04-24 下午11.35.28.png

相关文章

网友评论

      本文标题:判断是否点击了某个图层

      本文链接:https://www.haomeiwen.com/subject/pydogqtx.html