How can I check if a user tapped near a CGPath?

后端 未结 3 1732
终归单人心
终归单人心 2020-12-05 08:35

Scenario:

I have a set of CGPaths. They are mostly just lines (i.e. not closed shapes). They are drawn on the screen in a UIView\'s draw

3条回答
  •  隐瞒了意图╮
    2020-12-05 09:39

    In iOS 5.0 and later, this can be done more simply using CGPathCreateCopyByStrokingPath:

    CGPathRef strokedPath = CGPathCreateCopyByStrokingPath(path, NULL, 15,
        kCGLineCapRound, kCGLineJoinRound, 1);
    BOOL pointIsNearPath = CGPathContainsPoint(strokedPath, NULL, point, NO);
    CGPathRelease(strokedPath);
    
    if (pointIsNearPath) ...
    

提交回复
热议问题