嗨,我正在一个必须画点东西的应用程序上。当我用标记笔触绘制时会产生一些边缘,如何避免出现这些边缘?




标记笔触代码

- (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];
}

最佳答案

您应该使用kCGLineJoinRound函数将线连接设置为CGContextSetLineJoin。有关更多信息,请参见Quartz 2D Guide

更新

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

09-13 10:53