【问题标题】:Clipping parent view by subview and put content of first one in second one but scaled通过子视图剪切父视图并将第一个的内容放在第二个但缩放
【发布时间】:2012-06-10 13:11:47
【问题描述】:

问题是……

我有一个父视图,在其中我绘制了一个由许多 CGPath 组成的平面图。 好吧,在这个应用程序中,我可以将一个子视图插入到父视图中,其中绘制了其他 CGPath(例如代表椅子的线条)。现在。我会复制 UITextView 的缩放效果,当有人点击向下,按住点击,然后一个手玻璃出现,内容被缩放。

我会放置一个子视图,其中的背景表示父内容在子视图矩形中剪辑并缩放 x2。这样,子视图背景就像父视图上的手玻璃。

我该如何实现这个?

我考虑过获取父上下文,将其传递给子视图,并使用矩形子视图剪切父上下文。但什么也没有发生。我对 CGImageContext 表示红色,女巫对父 CGContext 进行图像表示,并将其传递给子视图,但我不知道如何实现它。而且,我不知道这是否正确。

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

对不起我的英语。我尽力了:)

【问题讨论】:

    标签: ios uiview cgcontext clipping cgpath


    【解决方案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];
    }
    

    希望这可以帮助其他人:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多