开发者

How do I keep the text sharp while zooming when using a CATiledLayer to render a PDF

I have implemented a PDF viewer in my app. It's a scroll view which uses CATiledLayer for zooming.

A simpler approach would have been to use QLPreviewController, which supports PDF viewing with page control and zooming but I need fine control over the PDF page.

I have the viewer working but w开发者_如何学JAVAould like the redraw to kick in sooner. At the moment it only redraws the text when I zoom in to double the size (200%). So the text appears blurry until you zoom in far enough.

I have tried various combinations of levelOfDetail and levelOfDetailBias to try and get the re-drawing to occur sooner but to no avail.

Here is the code which creates the CATiledLayers:

  //get the pdf crop box rectangle
  CGPDFPageRef pageRef=[self.pdf getPdfPage:self.myPageNo];
  CGRect cropBox = CGRectIntegral(CGPDFPageGetBoxRect(pageRef, kCGPDFCropBox));

  //scale to size of the screen
  CGRect targetRect = self.view.bounds;
  CGFloat xScale = targetRect.size.width / cropBox.size.width;
  CGFloat yScale = targetRect.size.height / cropBox.size.height;
  self.scale = xScale < yScale ? xScale : yScale;

  //alway fill height of screen
  self.scale = yScale;

  //used to center the pdf horizontally
  self.xOffSet = (targetRect.size.width - cropBox.size.width*self.scale)/2;
  [self renderPDFPageToImage];
  CGRect boundsRect = self.view.bounds;

  //use a tiled layer for better performance
  CATiledLayer *tiledLayer = [CATiledLayer layer];
  tiledLayer.delegate = self;
  tiledLayer.tileSize = CGSizeMake(1024.0, 1024.0);
  tiledLayer.levelsOfDetail = 4;
  tiledLayer.levelsOfDetailBias = 4;
  tiledLayer.frame = boundsRect;

  self.myContentView = [[[UIView alloc] initWithFrame:boundsRect] autorelease];
  [self.myContentView.layer addSublayer:tiledLayer];

  CGRect viewFrame = self.view.frame;
  viewFrame.origin = CGPointZero;
  UIScrollView *_scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
  _scrollView.delegate = self;
  _scrollView.contentSize = boundsRect.size;

  _scrollView.maximumZoomScale = 4;
  [_scrollView addSubview:myContentView];
  //retain it
  self.scrollView=_scrollView;

  [self.view addSubview:_scrollView];
  [_scrollView release];

Please point me in the right direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜