2011-03-11 3 views
3

CGContext의 ShowTextAtPoint 메소드를 사용하여 뷰에 텍스트를 표시하지만 플립 모드로 표시되면 누구든지이 문제를 해결하는 방법을 알고 있습니까?ShowTextAtPoint를 사용하여 표시된 텍스트 뒤집기

ctx.SelectFont("Arial", 16f, CGTextEncoding.MacRoman); 
ctx.SetRGBFillColor(0f, 0f, 1f, 1f); 
ctx.SetTextDrawingMode(CGTextDrawingMode.Fill); 
ctx.ShowTextAtPoint(centerX, centerY, text); 

답변

0

그림 16-1에서와 같이 아이폰 OS에서

, 당신은 텍스트의 순서를 현재 그래픽 컨텍스트에 변환을 적용해야이 지향한다. 이 변환 은 y 축을 반전합니다.은 원점을 화면 하단의으로 변환합니다. Listing 16-2는 iOS 뷰의 drawRect : 메소드에서 그러한 변환을 적용하는 방법을 보여준다. 그런 다음이 메소드는 Listing 16-1과 동일한 MyDrawText 메소드를 호출하여 동일한 결과를 얻는다.

방법이 MonoTouch에서 찾습니다 :

public void DrawText(string text, float x, float y) 
{ 
    // the incomming coordinates are origin top left 
    y = Bounds.Height-y; 

    // push context 
    CGContext c = UIGraphics.GetCurrentContext(); 
    c.SaveState(); 

    // This technique requires inversion of the screen coordinates 
    // for ShowTextAtPoint 
    c.TranslateCTM(0, Bounds.Height); 
    c.ScaleCTM(1,-1); 

    // for debug purposes, draw crosshairs at the proper location 
    DrawMarker(x,y); 

    // Set the font drawing parameters 
    c.SelectFont("Helvetica-Bold", 12.0f, CGTextEncoding.MacRoman); 
    c.SetTextDrawingMode(CGTextDrawingMode.Fill); 
    c.SetFillColor(1,1,1,1); 

    // Draw the text 
    c.ShowTextAtPoint(x, y, text); 

    // Restore context 
    c.RestoreState(); 
} 

원하는 지점에서 십자선을 그리는 작은 유틸리티 기능 :

public void DrawMarker(float x, float y) 
{ 
    float SZ = 20; 

    CGContext c = UIGraphics.GetCurrentContext(); 

    c.BeginPath(); 
    c.AddLines(new [] { new PointF(x-SZ,y), new PointF(x+SZ,y) }); 
    c.AddLines(new [] { new PointF(x,y-SZ), new PointF(x,y+SZ) }); 
    c.StrokePath(); 
} 
1

당신은 ScaleCTM 및 TranslateCTM를 사용하여 플립 그래픽 컨텍스트의 현재 변환 행렬을 조작 할 수있다 : 여기서 I 사용하는 코드이다. Quartz 2D Programming Guide - Text에 따르면

+0

당신이 사용 예를 가리시겠습니까? 감사. –

관련 문제