Permalink
Browse files

Correct rendering scale in retina display.

  • Loading branch information...
1 parent 5049970 commit 8681006a4d7bda13387e515d9432f64181c832b8 @xissburg xissburg committed Feb 13, 2012
Showing with 13 additions and 6 deletions.
  1. +5 −4 transform/framework/FlipView.m
  2. +8 −2 transform/framework/GenericAnimationView.m
View
9 transform/framework/FlipView.m
@@ -75,6 +75,7 @@ - (BOOL)printText:(NSString *)tickerString
backgroundColor:(UIColor *)aBackgroundColor
textColor:(UIColor *)aTextColor
{
+ CGFloat scale = [[UIScreen mainScreen] scale];
if ([super printText:tickerString usingImage:aImage backgroundColor:aBackgroundColor textColor:aTextColor]) {
switch (self.animationType) {
@@ -140,9 +141,9 @@ - (BOOL)printText:(NSString *)tickerString
shadowLayer4.transform = CATransform3DMakeRotation(M_PI, 1.0, 0, 0);
[flipLayer2 addSublayer:shadowLayer4];
- CGImageRef imageRef = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, 0, templateWidth, templateHeight/2));
+ CGImageRef imageRef = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, 0, templateWidth*scale, templateHeight*scale/2));
- CGImageRef imageRef2 = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, templateHeight/2, templateWidth, templateHeight/2));
+ CGImageRef imageRef2 = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, templateHeight*scale/2, templateWidth*scale, templateHeight*scale/2));
[backLayer setContents:(id)imageRef];
[backLayer2 setContents:(id)imageRef2];
@@ -218,9 +219,9 @@ - (BOOL)printText:(NSString *)tickerString
shadowLayer4.transform = CATransform3DMakeRotation(M_PI, 0, 1.0, 0);
[flipLayer2 addSublayer:shadowLayer4];
- CGImageRef imageRef = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(templateWidth/2, 0, templateWidth/2, templateHeight));
+ CGImageRef imageRef = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(templateWidth*scale/2, 0, templateWidth*scale/2, templateHeight*scale));
- CGImageRef imageRef2 = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, 0, templateWidth/2, templateHeight));
+ CGImageRef imageRef2 = CGImageCreateWithImageInRect([templateImage CGImage], CGRectMake(0, 0, templateWidth*scale/2, templateHeight*scale));
[backLayer setContents:(id)imageRef2];
[backLayer2 setContents:(id)imageRef];
View
10 transform/framework/GenericAnimationView.m
@@ -92,6 +92,7 @@ - (BOOL)printText:(NSString *)tickerString
if (tickerString) {
CALayer *backingLayer = [CALayer layer];
+ backingLayer.contentsGravity = kCAGravityResizeAspect;
// set opaque to improve rendering speed
backingLayer.opaque = YES;
@@ -110,6 +111,7 @@ - (BOOL)printText:(NSString *)tickerString
CATextLayer *label = [CATextLayer layer];
// for crisp text, set text layer to screen resolution
label.contentsScale = [[UIScreen mainScreen] scale];
+ label.contentsGravity = kCAGravityResizeAspect;
label.string = tickerString;
label.font = font;
label.fontSize = fontSize;
@@ -126,9 +128,12 @@ - (BOOL)printText:(NSString *)tickerString
[backingLayer addSublayer:label];
- UIGraphicsBeginImageContext(backingLayer.frame.size);
+ CGFloat scale = [[UIScreen mainScreen] scale];
+ CGSize size = CGSizeMake(backingLayer.frame.size.width*scale, backingLayer.frame.size.height*scale);
+ UIGraphicsBeginImageContextWithOptions(size, NO, scale);
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ [backingLayer renderInContext:context];
- [backingLayer renderInContext:UIGraphicsGetCurrentContext()];
templateImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@@ -160,6 +165,7 @@ - (CALayer *)layerWithFrame:(CGRect)aFrame
layer.doubleSided = NO;
layer.masksToBounds = YES;
layer.doubleSided = NO;
+ layer.contentsGravity = kCAGravityResizeAspect;
return layer;
}

0 comments on commit 8681006

Please sign in to comment.