2
在我的CATiledLayerDelegate我有以下代碼來繪製一個PDF頁面。這有效,但我不明白爲什麼! CATiledLayer應該問我瓷磚畫。下面的代碼總是繪製完整的PDF頁面。不過,我可以看到瓷磚一個接一個出現。這是如何運作的?DrawPdfPage()如何在CATiledLayer中使用時知道要繪製哪些部分?
如果我是CATiledLayer的子類,我可以重寫drawRect:它要求我繪製一個特定的矩形,但使用委託不是這種情況。那麼這個魔法是如何工作的?
public override void DrawLayer (CALayer layer, CGContext context)
{
context.SaveState();
context.SetRGBFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (context.GetClipBoundingBox());
context.TranslateCTM (0.0f, layer.Bounds.Size.Height);
context.ScaleCTM (1.0f, -1.0f);
context.ConcatCTM (this.oParentController.oPdfPage.GetDrawingTransform (CGPDFBox.Media, layer.Bounds, 0, true));
context.DrawPDFPage (this.oParentController.oPdfPage);
context.RestoreState();
}