diff --git a/Leaves/LeavesCache.h b/Leaves/LeavesCache.h index b45f83a..8526101 100644 --- a/Leaves/LeavesCache.h +++ b/Leaves/LeavesCache.h @@ -14,8 +14,9 @@ @property (nonatomic, assign) CGSize pageSize; @property (assign) id dataSource; +@property (readonly) CGFloat scaleFactor; -- (id)initWithPageSize:(CGSize)aPageSize; +- (id)initWithPageSize:(CGSize)aPageSize andScaleFactor:(CGFloat)scaleFactor; - (CGImageRef)cachedImageForPageIndex:(NSUInteger)pageIndex; - (void)precacheImageForPageIndex:(NSUInteger)pageIndex; - (void)minimizeToPageIndex:(NSUInteger)pageIndex; diff --git a/Leaves/LeavesCache.m b/Leaves/LeavesCache.m index 01c4012..f0d218e 100644 --- a/Leaves/LeavesCache.m +++ b/Leaves/LeavesCache.m @@ -17,11 +17,12 @@ @interface LeavesCache () @implementation LeavesCache -- (id)initWithPageSize:(CGSize)aPageSize +- (id)initWithPageSize:(CGSize)aPageSize andScaleFactor:(CGFloat)fScaleFactor { if (self = [super init]) { _pageSize = aPageSize; _pageCache = [[NSMutableDictionary alloc] init]; + _scaleFactor = fScaleFactor; } return self; } @@ -38,12 +39,15 @@ - (CGImageRef)imageForPageIndex:(NSUInteger)pageIndex { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, - self.pageSize.width, - self.pageSize.height, + self.pageSize.width * self.scaleFactor, + self.pageSize.height * self.scaleFactor, 8, /* bits per component*/ - self.pageSize.width * 4, /* bytes per row */ + self.pageSize.width * 4 * self.scaleFactor, /* bytes per row */ colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + + CGContextScaleCTM(context, self.scaleFactor, self.scaleFactor); + CGColorSpaceRelease(colorSpace); CGContextClipToRect(context, CGRectMake(0, 0, self.pageSize.width, self.pageSize.height)); diff --git a/Leaves/LeavesView.m b/Leaves/LeavesView.m index 5a4aba7..26c946f 100644 --- a/Leaves/LeavesView.m +++ b/Leaves/LeavesView.m @@ -22,6 +22,7 @@ @interface LeavesView () @property (nonatomic, assign) CGRect nextPageRect, prevPageRect; @property (nonatomic, assign) BOOL touchIsActive, interactionLocked; @property (readonly) LeavesCache *pageCache; +@property (readonly) CGFloat scaleFactor; @end @@ -78,6 +79,16 @@ - (void)initCommon { nil]; _bottomPageShadow.startPoint = CGPointMake(0,0.5); _bottomPageShadow.endPoint = CGPointMake(1,0.5); + + _scaleFactor = 1.0; + + // Check if iOS > 4 + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){ + _topPage.contentsScale = \ + _topPageReverseImage.contentsScale = \ + _bottomPage.contentsScale = \ + _scaleFactor = [[UIScreen mainScreen] scale]; + } [_topPage addSublayer:_topPageShadow]; [_topPage addSublayer:_topPageOverlay]; @@ -89,9 +100,9 @@ - (void)initCommon { [self.layer addSublayer:_topPage]; [self.layer addSublayer:_topPageReverse]; - _leafEdge = 1.0; + _leafEdge = 1.0; _backgroundRendering = NO; - _pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size]; + _pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size andScaleFactor: self.scaleFactor]; } - (id)initWithFrame:(CGRect)frame {