2011-12-18 4 views
2

Quartz 2D를 처음 사용했습니다. 삼각형을 그려서 회전하려고합니다. Quartz 2D를 사용하는 나의 제한된 배경에서 나는 Apple/googling에서 발견하여 CGContextRotateCTM 함수를 사용할 수있다. 내 문제는 그 이후에 그려진 전체 텍스트도 회전된다는 것입니다. CGContextSaveGstate을 사용하여 시도하고 난 후 회전하지만 didnt 작업을 복원. 내 접근 방식이 맞는지 궁금하네요? 아니면 그것을 달성하는 데 사용할 수있는 더 나은 방법이 있습니까?석영 2D 드로잉 프리미티브 회전

CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSaveGState(context); 
    for (key in data) 
    { 
    // get point 
    Data *tmpdata =[data objectForKey:key] ; 
    point=[data point ] 
    //setup and draw the 
    CGContextBeginPath(context); 
    CGContextSetRGBFillColor(context, [data fillcolor].r, 
     [data fillcolor].g, [tmpACdata fillcolor].b, 1); 
    CGContextSetLineWidth(context, 2.0 

    // Draw Triangle   
    CGContextMoveToPoint(context,point.x,point.y); 
    CGContextAddLineToPoint(context, point.x+8, point.y+8); 
    CGContextAddLineToPoint(context, point.x-8, point.y+8); 

    CGContextClosePath(context); 
    CGContextDrawPath(context, kCGPathFill); 

    CGContextRotateCTM(context, [data heading]* M_PI/180); 

    CGContextClosePath(context); 
    CGContextDrawPath(context, kCGPathFill); 
    // Draw Text 
    ............... 
    } 
    CGContextRestoreGState(context); 

답변

2

이 시도 : 죄송합니다에만 다음

// Draw Text 
+0

로직을 시도했지만 작동하지 않았습니다. 이제 텍스트가 표시되지만 삼각형은 표시되지 않습니다. – user519274

+0

좌표에 문제가있는 경우 관련 행이있는 코드를 입력하십시오. 아니면'std :: cout << yourVariable << "\ n"을 던져라. – Adrian

0
CGContextRotateCTM(context, [data heading]* M_PI/180); 

CGContextClosePath(context); 
CGContextDrawPath(context, kCGPathFill); 

CGContextRotateCTM(context, -[data heading]* M_PI/180); 

// Draw Text 
+0

정말 고맙습니다. 그것의 일하는 것은 일하고 있습니다. 그려진 삼각형이 정확한 회전으로 보이지만, 적절한 위치에있는 것은 아닙니다. 반면에 텍스트는 올바른 위치에 그려집니다. – user519274

+0

다시 연락하지 않으셔서 죄송합니다. 회전은 왼쪽 상단부터 시작하여 장면의 중심으로 변환 한 다음 회전 한 다음 다시 번역 한 다음 draw1 – Nico

3

좋아

CGContextSaveGState(context); 
CGContextRotateCTM(context, [data heading]* M_PI/180); 
// draw triangle 
CGContextRestoreGState(context); 

과 다시 충분히 빨리 재생 결승전의 커플을 마무리했다하지 않는. 나는 당신이 지적한 바를 정확하게 수행했고, 제대로 작동 시켰습니다. 코드가 다른 사람에게 도움이 될 수도 있습니다.

CGContextSaveGState(context); 
CGContextBeginPath(context);   
CGContextTranslateCTM(context, point.x, point.y); 
//CGContextScaleCTM(context, 1.0, -1.0); that didnt work   
CGContextRotateCTM(context, [data heading]* M_PI/180) ; 
CGContextSetRGBFillColor(context, [data fillcolor].r, [data fillcolor].g, [data fillcolor].b, 1); 

//Draw Triangle 
CGContextMoveToPoint(context,0,0); 
CGContextAddLineToPoint(context, 10, 10); 
CGContextAddLineToPoint(context, 0, 6); 
CGContextAddLineToPoint(context, -10,10);    
CGContextRotateCTM(context,(-1.0)* [tmpACdata heading]* M_PI/180); 
CGContextClosePath(context); 
CGContextDrawPath(context, kCGPathFill);' 
CGContextRestoreGState(context); 

도움을 주셔서 감사합니다. 실용적인 Quartz 2D 서적에 대한 제안이 있습니까? Apple doc은 조금 도움이되었지만 그 개념을 이해하는 데 큰 도움이되지는 못했습니다.