2012-03-16 4 views
2

안녕하세요, 저는 무언가를 그려야하는 응용 프로그램을 만들고 있습니다. 마커 스트로크로 그릴 때 가장자리가 생기고 어떻게 이러한 가장자리를 피할 수 있습니까? 마커 스트로크iPhone의 마커 획을 부드럽게 만드는 방법은 무엇입니까?

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

중복 되었습니까? http://stackoverflow.com/questions/5076622/iphone-smooth-sketch-drawing-algorithm – basvk

+0

예 코드와 고맙습니다 @ basvk을 추가했습니다. 도움이된다고 생각합니다. – Mashhadi

답변

1

어떻게 당신이 그 곡선을 그리는 대한 enter image description here

코드? 일련의 짧은 직선 세그먼트를 그릴 경우 문제가 발생합니다. 베 지어 경로로 이러한 종류의 커브를 그려야합니다. 이미 베 지어 경로를 사용중인 경우 flatness 속성을 조정해야 할 수 있습니다.

+0

이미 베 지어를 사용하고 있습니다. – Mashhadi

4

CGContextSetLineJoin 기능을 사용하여 라인 조인을 kCGLineJoinRound으로 설정해야합니다. 자세한 내용은 Quartz 2D Guide을 참조하십시오.

UPDATE

당신이 UIBezierPath을 사용하고 있기 때문에, 당신은 kCGLineJoinRoundUIBezierPathlineJoinStyle 설정을 시도해야합니다.

+0

+1 우수 포인트. – Caleb

관련 문제