Pregunta

Estoy usando CGContextShowText para mostrar el texto, pero al girarlo con CGAffineTransformation , el eje de rotación está ubicado a la izquierda, no al centro del texto dibujado, El código que estoy usando es este:

CGContextSaveGState(context);

CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, 1);
CGContextSetRGBFillColor (context, 0, 0, 0, 1);
CGAffineTransform xform = CGAffineTransformMake(
    sin(DegreesToRadians(angle)), cos(DegreesToRadians(angle)),
    cos(DegreesToRadians(angle)), -sin(DegreesToRadians(angle)),
    0,  0);

CGContextSetTextDrawingMode (context, kCGTextFill); 

CGPoint degreeDisplayPoint = CGPointMake(100,100);
CGContextShowTextAtPoint(context, degreeDisplayPoint.x, degreeDisplayPoint.y, [angleStringWithDegree cStringUsingEncoding:NSMacOSRomanStringEncoding], [angleStringWithDegree length]); 

CGContextRestoreGState(context);

¿Alguna idea?

¿Fue útil?

Solución

Convierta su objeto de modo que su centro esté en (0, 0), luego gírelo y luego vuelva a traducirlo a donde desee.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top