第一种方法:使用closePath
UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath movetoPoint:CGPointMake(x,y)]; [bpath addLinetoPoint:CGPointMake(x + w,y + h)]; [bpath addLinetoPoint:CGPointMake(x,y + h)]; [bpath closePath];
输出:
UIBezierPath *bpath = [UIBezierPath bezierPath]; [bpath movetoPoint:CGPointMake(x,y)];
输出:
在closePath的文档中,它说这个方法通过在子路径中的第一个和最后一个点之间创建一个线段来关闭当前子路径.此方法随后将当前点更新为新创建的线段的末尾,这也是现在关闭的子路径中的第一个点.
解决方法
如果使用[closePath],则会将另一个类型为kCGpathelementCloseSubpath的CGpathelement追加到该最后一个线段之后的路径末尾.
当从文档中使用UIBezierPath的[containsPoint:]方法时,这一点尤为重要:
A point is not considered to be enclosed by the path if it is inside an open subpath,regardless of whether that area would be painted during a fill operation. Therefore,to determine mouse hits on open paths,you must create a copy of the path object and explicitly close any subpaths (using the closePath method) before calling this method.
原文地址:https://www.jb51.cc/iOS/334489.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。