![](/img/trans.png)
[英]How to put CGContextScaleCTM and CGContextTranslateCTM outside of drawRect?
[英]How to correctly update a uiview magnified and translated with CGContextScaleCTM and CGContextTranslateCTM
我有一個uiview B,它打算被另一個uiview A放大(“ touchPoint”周圍的區域)。 當“ touchPoint”更改時,我希望B更新其顯示。 我在B中具有以下函數,並且確實會進行更新(當我調用B.setNeedsDisplay()時),但是它使舊內容保持某種可見性,例如褪色的背景圖像。 你們知道為什么仍然顯示舊內容以及為什么這種褪色的效果嗎? 是因為我要放大的區域具有透明背景嗎? 如何解決?
override func drawRect(rect: CGRect)
{
let context: CGContextRef = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5))
CGContextScaleCTM(context, 1.5, 1.5)
CGContextTranslateCTM(context,-1*(touchPoint.x),-1*(touchPoint.y))
viewToMagnify.layer.renderInContext(context)
}
我本想發布一張圖片,但是我沒有足夠的stackOverflow點... :-)
感謝您的指導!
找到了我自己問題的答案。
必須在drawRect函數的開頭清除放大視圖的上下文,其中包括以下內容:
CGContextClearRect(context, rect)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.