开发者

How to make the subview in a UIScrollView to refresh when we zoom it?

I have subclassed UIView object inside a uiscrollview which displays a pdf page. I can zoom that page. But when I do so, the inside view is zoomed and is getting blurred. I understood that the inner view shud be refreshed and i called setNeedsDisplay. But no change have happened and its the same even now. Below is the code for drawRect for the subclassed uiview.

- (void)drawRect:(CGRect)rect
{
if(document)//the pdf document object
{       
    CGContextRef ctx = UIGraphicsGetC开发者_JAVA百科urrentContext();
    CGContextSaveGState(ctx);
    CGContextTranslateCTM(ctx, 0.00, [self bounds].size.height);
    NSLog(@"%f",[self bounds].size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, 
                                                         [self bounds], 0, true));
    CGContextDrawPDFPage(ctx, page);    
    CGContextRestoreGState(ctx);
}
}


Check out the CATiledLayer example provided by the ScrollViewSuite sample code:

http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Introduction/Intro.html

The TapToZoom example illustrates a way to get the view to redraw its content when one zooms in. I.e. you need to somehow set your view's frame to be larger than the screen, or maybe you can also use transforms - however, I never used transforms before.


A bit late to answer, just as pointed out you have to set the frame of subview's each time when zoom is applied. Make sure that you backup the original frame dimensions so that you apply the zoom factor over it.

Scroll view does not change the frame of its subviews when it zooms the subviews, that is why the subview's contents are not refreshed. I found using transforms and others complex, so I just tried the mentioned method, and it worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜