Performance scrolling and retina resolution images in CALayer

IphoneIos

Iphone Problem Overview


I have a UIView that is placed as a subview in a UIScrollView. I have several child views made up of images, text, and buttons in the UIView. In order to get decent scrolling performance I set shouldRasterize = YES on the layer in the UIView. This worked great in that performance increased so I have smooth scrolling and doesn't pose an issue since my graphics are static once drawn. However, the problem is that when I set shouldRasterize that the rasterized graphics are blurry and low resolution on a Retina display. Is there a way to have high resolution graphics that are rasterized for performance?

Iphone Solutions


Solution 1 - Iphone

Seems I needed to set rasterizationScale to the proper value for the device as follows.

myView.layer.rasterizationScale = [[UIScreen mainScreen] scale];

Solution 2 - Iphone

I had a similar problem-- a rotated UIView with several UIImageView subviews. When I set the rasterizationScale = 2.0, the images became crisper, but this caused serration to reemerge. To fix this, I created a containerView that held the UIView and UIIMageViews (which were previously subviews of the UIView) and applied rasterizationScale = 1.0 to the UIView and rasterizationScale = 2.0 to the UIImageViews. Now everything looks quite nice.

Solution 3 - Iphone

@Jamie Hamick's answer in Swift 5:

myView.layer.rasterizationScale = UIScreen.main.scale

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamie HamickView Question on Stackoverflow
Solution 1 - IphoneJamie HamickView Answer on Stackoverflow
Solution 2 - Iphoneastrojams1View Answer on Stackoverflow
Solution 3 - IphoneAkash KunduView Answer on Stackoverflow