Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blurry UIView with CATransform3D only on RETINA

I'm displaying a UIView with a UILabel on it and this view&label become blurry as soon as it gets to these lines code:

CATransform3D transform = CATransform3DIdentity;      
transform.m34 = (1.0/-500);
view.layer.transform = transform;

Throughout the App I use CA3DRotations and other stuff and this never happened before. Also, I set the frame of the view and the label only using integers! So it's not a half-pixel problem or something like that, I know that that causes most blurry problems, but not mine!

On the simulator it's not blurry, iPad is not blurry, iPhone3GS is not blurry. Only on an iPhone4 with Retina display it becomes blurry. Even before I do any 3D rotations! Does anybody have a clue before I go insane?

like image 406
Bob de Graaf Avatar asked Mar 14 '12 13:03

Bob de Graaf


2 Answers

Alright, I've found a solution. After using a hundred different lines of code using layer properties, such as layer gravity or magnification and tons of other solutions I suddenly stumbled by accident on the following 2 lines:

self.layer.shouldRasterize = TRUE;
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];

This is the solution! For everyone in the future, is your view blurry on retina displays? Use this!

like image 63
Bob de Graaf Avatar answered Oct 18 '22 17:10

Bob de Graaf


Have you set the contentsScale for the layer to match [UIScreen mainScreen]. scale? Try it.

like image 30
cxa Avatar answered Oct 18 '22 16:10

cxa