作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我发现 iOS 5.0 上的 CGPathCreateCopyByStrokingPath 使用起来非常方便,但它在 iOS 5 及更高版本上可用。
有什么简单的方法可以在iOS 4上实现同路径复制吗?
最佳答案
我用的是这个,它兼容 IOS5 和 IOS4+。如果您使用相同的填充 + 描边颜色,它会 100% 有效。 Apple 的文档对此有点阴暗 - 他们说“如果你填充它就可以工作”,他们没有说“如果你抚摸它就会有点错误” - 但在那种情况下它似乎有点错误。 YMMV.
// pathFrameRange: you have to provide something "at least big enough to
// hold the original path"
static inline CGPathRef CGPathCreateCopyByStrokingPathAllVersionsOfIOS( CGPathRef
incomingPathRef, CGSize pathFrameRange, const CGAffineTransform* transform,
CGFloat lineWidth, CGLineCap lineCap, CGLineJoin lineJoin, CGFloat miterLimit )
{
CGPathRef result;
if( CGPathCreateCopyByStrokingPath != NULL )
{
/**
REQUIRES IOS5!!!
*/
result = CGPathCreateCopyByStrokingPath( incomingPathRef, transform,
lineWidth, lineCap, lineJoin, miterLimit);
}
else
{
CGSize sizeOfContext = pathFrameRange;
UIGraphicsBeginImageContext( sizeOfContext );
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, lineWidth);
CGContextSetLineCap(c, lineCap);
CGContextSetLineJoin(c, lineJoin);
CGContextSetMiterLimit(c, miterLimit);
CGContextAddPath(c, incomingPathRef);
CGContextSetLineWidth(c, lineWidth);
CGContextReplacePathWithStrokedPath(c);
result = CGContextCopyPath(c);
UIGraphicsEndImageContext();
}
}
关于ios - CGPathCreateCopyByStrokingPath 等同于 iOS4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7776931/
正如标题所说,我想知道是否可以在不创建路径副本的情况下创建路径。基本上我需要这样做的原因是因为我需要一个可以使用 CGpathcontainspoint 的路径。 CGPathMoveToPoint
我发现 iOS 5.0 上的 CGPathCreateCopyByStrokingPath 使用起来非常方便,但它在 iOS 5 及更高版本上可用。 有什么简单的方法可以在iOS 4上实现同路径复制吗
Core Graphics有两个功能,CGPathCreateCopyByDashingPath()和CGPathCreateCopyByStrokingPath() ,两者都采用您想要描边的 CGP
我是一名优秀的程序员,十分优秀!