【问题标题】:Text is getting blurred after zooming缩放后文字变得模糊
【发布时间】:2014-05-09 07:52:27
【问题描述】:

我的scrollView 是这样的UIViewController --> UIView -->UIScrollView。在滚动视图中,我尝试缩放 PDF 文件。缩放后pdf文件的内容变得模糊。

- (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer
{
for (MagazinePage * page in [self.contentScroll subviews]) {
//maganizepage is a subclass of UIView
//contentScroll is a UIScrollView
    [page removeFromSuperview];
}
int i = 0;
zoomScaleValue = zoomScaleValue+500;

self.contentScroll.contentSize = CGSizeMake((self.contentScroll.bounds.size.width+zoomScaleValue) * NO_OF_PAGES_ON_MEMORY,
                                            self.contentScroll.bounds.size.height+zoomScaleValue);
for (MagazinePage * page in collection) {
      page.frame = CGRectMake((i) * self.contentScroll.bounds.size.width+(i*zoomScaleValue), 0.0f,
                                self.contentScroll.bounds.size.width+zoomScaleValue, self.contentScroll.bounds.size.height+zoomScaleValue);

    i++;
    [self.contentScroll addSubview:page];
    }
}

Edit:

-(void)viewDidLoad
{
CFURLRef pdfURL = (__bridge CFURLRef)[NSURL fileURLWithPath:pdfFilePath]; 
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL); 
self.contentScroll.delegate = self; 
self.contentScroll.contentSize = CGSizeMake(self.contentScroll.bounds.size.width * noofpages, self.contentScroll.bounds.size.height);
 CGPDFDocumentRelease(pdf); collection = [NSMutableArray array];
for (int i = 1; i <= noofpages; i++) { 
    uiviewObject = [[MyUIViewClass alloc] initWithFrame:CGRectMake((i-1) * self.contentScroll.bounds.size.width, 0.0f,self.contentScroll.bounds.size.width, self.contentScroll.bounds.size.height)];
     //uiviewObject subclass of UIView 
    uiviewObject.pdfFileName = pdfName; 
    uiviewObject.pdfFilePath = pdfPath; 
    uiviewObject.pageNumber = _scrollPageNumberToLoad;
     uiviewObject.navigationDelegate = self; 
    [collection addObject:uiviewObject]; 
} 
    [self loadCollectionToContentScroll: collection]; 
}



- (void) loadCollectionToContentScroll: (NSMutableArray *) collectionItems {
for (uiviewObject in [self.contentScroll subviews]) { 
[uiviewObject removeFromSuperview]; 
}
 int i = 0; 
for (uiviewObject in collectionItems) {
uiviewObject.frame = CGRectMake((i) * self.contentScroll.bounds.size.width, 0.0f, self.contentScroll.bounds.size.width, self.contentScroll.bounds.size.height);
i++; 
[self.contentScroll addSubview:uiviewObject];
    }
}

【问题讨论】:

标签: ios uiview uiscrollview zooming


【解决方案1】:

您必须在您的 UIView 类中添加此方法以支持平铺,从而防止您的 PDF 内容被模糊。

+ (Class)layerClass
{
    return [YourCustomContentTile class];
}

YourCustomContentTile.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface YourCustomContentTile :  CATiledLayer {

}

@end

YourCustomContentTile.m

@implementation YourCustomContentTile

- (id)init
{
    if ((self = [super init]))
    {
        self.levelsOfDetail = 5;

        self.levelsOfDetailBias = (5 - 1);

        CGFloat screenScale;

        UIScreen *mainScreen = [UIScreen mainScreen];

        if ([mainScreen respondsToSelector:@selector(scale)])
            screenScale = [mainScreen scale];
        else
            screenScale = 1.0f;

        CGRect screenBounds = [mainScreen bounds]; 

        CGFloat w_pixels = (screenBounds.size.width * screenScale);
        CGFloat h_pixels = (screenBounds.size.height * screenScale);

        CGFloat max = (w_pixels < h_pixels) ? h_pixels : w_pixels;

        CGFloat sizeOfTiles = (max < 512.0f) ? 512.0f : 1024.0f;

        self.tileSize = CGSizeMake(sizeOfTiles, sizeOfTiles);
    }

    return self;
}

【讨论】:

  • 其实我没有单独的ScrollView类,把UIScrollView拖到UIViewController-->UIView上。并绑定此滚动视图。在 UIViewController 中,我正在使用该滚动视图。添加了上面的代码,但是效果和上面一样
  • 好的,没问题,把这个添加到你现有的类中看看。
  • + (Class)layerClass 没有调用,双击后我想这应该被调用,但是这个方法没有被调用。我必须调用这个方法,否则它会自动调用..
  • 您能告诉我您是如何将 PDF 页面绘制到您的视图上的吗??
  • 老兄请更新您的问题,代码在 cmets 中不可读。
猜你喜欢
  • 1970-01-01
  • 2019-11-11
  • 2020-08-27
  • 1970-01-01
  • 2015-12-23
  • 2015-11-06
  • 2019-12-24
  • 2012-04-21
  • 2018-09-01
相关资源
最近更新 更多