2012-06-06 24 views
0

的问题是...裁剪父视图,并把第一个内容在第二个,但规模

我有我画了一个由许多CGPaths组成的平面几何父视图。 那么,在这个应用程序中,我可以插入一个子视图到父视图中,其中绘制了其他CGPaths(例如表示椅子的线条)。现在。我会复制像UITextView一样的缩放效果,当有人按下按钮时,按住按钮,手持玻璃就会出现内容缩放。

我会放一个子视图,其中的背景代表在父视图剪裁在子视图rect和缩放x2例如。通过这种方式,子视图背景似乎是父母视图上的一把手。

我该如何实现?

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

希望有人可以帮助我(与代码示例将是可怕的)!

对不起,我的英语。我试图尽我所能:)

回答

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]; 
} 

希望这可以帮助别人:)

相关问题