0

円の内側にあるテキストを回転させる必要がありますが、円弧描画で中央に配置できませんでした。CGAffineTranformで回転することに成功しましたが、テキストは常に放射状の中央にありません。注:テキストは円弧の内側に配置されます。

float l_angleText=lStartAngle+((lStopAngle-lStartAngle)/2);
    CGContextSelectFont(p_contex, "Helvetica", 12.5, kCGEncodingMacRoman);

    CGAffineTransform myTransform=CGAffineTransformRotate(CGAffineTransformMakeScale(1,-1),-l_angleText);
    CGContextSetTextMatrix(p_contex, myTransform);

    CGContextSetTextDrawingMode(p_contex, kCGTextFill);
    CGContextSetRGBFillColor(p_contex, 1.0, 1.0, 1.0, 1.0); //White 

    // get x/y for an the angle. The point in which I start drawing the text.
    CGPoint lPoints = angleRToPoint(-l_angleText,[self getRadioPoint:l_angleText]);    

    //Move the point according the coords. 
    const double l_pointX = mReference.x+lPoints.x;
    const double l_pointY = mReference.y-lPoints.y;
    NSString* lText= [self getText];
    CGContextShowTextAtPoint(p_contex,  l_pointX, l_pointY, [lText UTF8String] , strlen([lText UTF8String]));
4

1 に答える 1

0

I;象限アプローチを使用して解決し、オフセットをsinacosで修正しました。このソリューションは、優れたエクスペリエンスを提供します。

-(CGPoint) getShiftToCenter:(const float) angle
{
    CGPoint lRet;
    unsigned int x = getCuadrante(angle);
    float rx,ry;
    switch (x) {
        case 1:
            rx=-sin(angle);
            ry=cos(angle);
            break;
        case 2:
            rx=cos(angle);
            ry=-cos(angle);
            break;
        case 3:
            rx=sin(angle);
            ry=-cos(angle);
            break;
        case 4:
            rx=-sin(angle);
            ry=cos(angle);
            break;
        default:
            break;
    }


    const float lFactor=4; // this is according to size of the font use it
    lRet.x=lFactor*rx;
    lRet.y=lFactor*ry;

    NSLog(@"Cuad %d , An %f ; x=%f - y=%f", x, angle, lRet.x,lRet.y);


    return  lRet;
}
于 2012-06-02T20:03:51.737 に答える