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?
Seems I needed to set rasterizationScale to the proper value for the device as follows.
myView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
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 UIIMageView
s (which were previously subviews of the UIView) and applied rasterizationScale = 1.0
to the UIView
and rasterizationScale = 2.0
to the UIImageView
s. Now everything looks quite nice.
@Jamie Hamick's answer in Swift 5:
myView.layer.rasterizationScale = UIScreen.main.scale
精彩评论