Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在iOS中用画笔画线_Objective C_Ios_Core Graphics_Cgcontext_Brush - Fatal编程技术网

Objective c 在iOS中用画笔画线

Objective c 在iOS中用画笔画线,objective-c,ios,core-graphics,cgcontext,brush,Objective C,Ios,Core Graphics,Cgcontext,Brush,这里有这么多的帖子,有人问如何在上下文中用画笔画线。答案总是:使用一种模式。然而,我已经尝试了几个小时,主要的问题是:CoreGraphics似乎只是简单地将图案绘制为填充,然后简单地用指定路径的笔划剪裁该图案。这会导致一些不好看的瓷砖边框,而且看起来不像是有人真的用手画的东西。我想要的是,画笔是沿着路径画的,没有任何剪辑。我基本上想沿着路径移动,只需在路径上每隔x点绘制笔刷图像,距离与笔刷大小相同。这在CoreGraphics中是可能的,还是您必须自己实现 //编辑:对不起,我想我说的很清楚,

这里有这么多的帖子,有人问如何在上下文中用画笔画线。答案总是:使用一种模式。然而,我已经尝试了几个小时,主要的问题是:CoreGraphics似乎只是简单地将图案绘制为填充,然后简单地用指定路径的笔划剪裁该图案。这会导致一些不好看的瓷砖边框,而且看起来不像是有人真的用手画的东西。我想要的是,画笔是沿着路径画的,没有任何剪辑。我基本上想沿着路径移动,只需在路径上每隔x点绘制笔刷图像,距离与笔刷大小相同。这在CoreGraphics中是可能的,还是您必须自己实现

//编辑:对不起,我想我说的很清楚,我使用了一种模式。这就是我目前所做的:

struct CGPatternCallbacks patternCallback = {0, drawChalkPattern, NULL};
CGAffineTransform patternTransform = CGAffineTransformMakeScale(.25f, .25f);

UIImage* brush = [UIImage imageNamed:@"ChalkBrush"];
CGPatternRef pattern = CGPatternCreate(NULL, (CGRect){CGPointZero, brush.size}, patternTransform, brush.size.width, brush.size.height, kCGPatternTilingConstantSpacingMinimalDistortion, true, &patternCallback);
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
CGContextSetStrokeColorSpace(context, patternSpace);

CGFloat color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
CGContextSetStrokePattern(context, pattern, color);

CGContextDrawPath(context, kCGPathStroke);
然后是patternCallback函数:

void drawChalkPattern(void * info, CGContextRef context) {
    UIImage* pattern = [UIImage imageNamed:@"ChalkBrush"];
    CGContextDrawImage(context, (CGRect){CGPointZero, pattern.size}, [pattern CGImage]);
}
致以最良好的祝愿, 迈克尔