我的scrollView就像这个UIViewController - > UIView - > UIScrollView。在scrollview中我试图缩放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];
}
}
答案 0 :(得分: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;
}