2012-06-06 29 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]; 
} 

希望這可以幫助別人:)

相關問題