通过子视图剪切父视图,并将第一个的内容放在第二个但缩放

时间:2012-06-06 13:51:27

标签: ios uiview cgcontext clipping cgpath

问题是......

我有一个父视图,其中我画了一个由很多CGPaths组成的平面测量法。 好吧,在这个应用程序中,我可以在父视图中插入子视图,其中绘制了其他CGPath(例如,代表椅子的线)。现在。我会像UITextView一样复制缩放效果,当有人点按,按住Tap,并且手持玻璃出现内容缩放时。

我会放置一个子视图,其中背景表示在子视图中剪切的父内容,例如缩放为x2。通过这种方式,子视图背景似乎是父视图上的手工玻璃。

我该如何实现?

我考虑过获取父上下文,将其传递给子视图,并使用rect子视图剪切父上下文。但没有任何反应。我嘲笑CGImageContext与女巫采取关于父CGContext的图像表示,并将其传递给子视图,但我不知道如何实现它。并且,我不知道它是否正确。

希望有人可以帮助我(代码示例会很棒)!

抱歉我的英文。我尽力了:))

1 个答案:

答案 0 :(得分:1)

我自己解决了问题!

在子视图中drawrect:方法我把这段代码:

- (void)drawRect:(CGRect)rect {
  // here we're just doing some transforms on the view we're magnifying,
  // and rendering that view directly into this view.
  // By 'touchPoint' i can select the exact portion of superview which
  // i want render in subview

   CGContextRef context = 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));
   [self.superview.layer renderInContext:context];
}

希望这可以帮助别人:)

相关问题