如何平滑iPhone的标记笔划?

时间:2012-03-16 14:16:07

标签: iphone drawing marker

嗨,我正在开发一个我需要画画的应用程序。当我用标记笔划绘制它会产生一些边缘,我怎么能避免这些边缘? enter image description here

enter image description here

标记笔划代码

- (void)drawRect:(CGRect)rect
{
//    KidsPhotoBookAppDelegate *appDelegate = (KidsPhotoBookAppDelegate*)[[UIApplication sharedApplication]delegate];
//    brushPattern = (UIColor*)appDelegate.kidsSelectedColor;

    DBManager *dbMgr = [DBManager sharedManager];
    [dbMgr.c setStroke];
    for (UIBezierPath *_path in pathArray) 
        [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];  
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    KidsPhotoBookAppDelegate *appDelegate = (KidsPhotoBookAppDelegate*)[[UIApplication sharedApplication]delegate];

    myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth = appDelegate.kidsBrushSize;
    myPath.lineCapStyle = kCGLineCapRound;
    brushPattern=appDelegate.kidsSelectedColor;
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath moveToPoint:[mytouch locationInView:self]];
    [pathArray addObject:myPath];

    appDelegate.viewContainsDrawing = YES;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath addLineToPoint:[mytouch locationInView:self]];

    [self setNeedsDisplay];
}

3 个答案:

答案 0 :(得分:4)

您应该使用kCGLineJoinRound功能将行加入设置为CGContextSetLineJoin。有关详情,请参阅Quartz 2D Guide

<强>更新

由于您使用的是UIBezierPath,因此您应该尝试将lineJoinStyle UIBezierPath设置为kCGLineJoinRound

答案 1 :(得分:1)

你是如何绘制这些曲线的?如果您正在绘制一系列短直线段,那就是问题所在。您应该使用贝塞尔曲线路径绘制这些曲线。如果您已经使用贝塞尔曲线路径,则可能需要调整flatness属性。

答案 2 :(得分:0)

借助此代码https://github.com/levinunnink/Smooth-Line-View

,我实现了这种顺畅