如何让 UIScrollView 中的子视图在缩放时刷新?

发布于 2024-08-24 09:40:07 字数 742 浏览 4 评论 0原文

我在显示 pdf 页面的 uiscrollview 中对 UIView 对象进行了子类化。我可以缩放该页面。但当我这样做时,内部视图会被放大并且变得模糊。我知道内部视图应该刷新,我调用了 setNeedsDisplay。但并没有发生任何变化,即使现在也是如此。下面是子类 uiview 的 drawRect 的代码。

- (void)drawRect:(CGRect)rect
{
if(document)//the pdf document object
{       
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    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);
}
}

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 = UIGraphicsGetCurrentContext();
    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);
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-08-31 09:40:07

查看 ScrollViewSuite 示例代码提供的 CATiledLayer 示例:

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

TapToZoom 示例说明了一种让视图在放大时重绘其内容的方法。即,您需要以某种方式设置你的视图框架比屏幕大,或者你也可以使用变换 - 但是,我以前从未使用过变换。

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.

攒眉千度 2024-08-31 09:40:07

回答有点晚了,正如指出的那样,每次应用缩放时都必须设置子视图的框架。确保备份原始框架尺寸,以便在其上应用缩放系数。

滚动视图在缩放子视图时不会更改其子视图的框架,这就是子视图的内容不会刷新的原因。我发现使用变换和其他方法很复杂,所以我只是尝试了提到的方法,它对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文