【问题标题】:How to correctly update a uiview magnified and translated with CGContextScaleCTM and CGContextTranslateCTM如何正确更新使用 CGContextScaleCTM 和 CGContextTranslateCTM 放大和翻译的 uiview
【发布时间】:2015-09-17 12:39:09
【问题描述】:

我有一个 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)
   }

我本来想发布一张图片,但我还没有足够的 * 积分... :-)

感谢您的指点!

【问题讨论】:

    标签: ios uiview drawrect setneedsdisplay cgcontextref


    【解决方案1】:

    找到了我自己问题的答案。

    必须在 drawRect 函数的开头清除放大视图的上下文,如下所示:

    CGContextClearRect(context, rect)

    【讨论】:

      最近更新 更多