Reputation: 3222
Currently, I have an UIImageView
that update its UIImage
every few seconds or so. This is an endless process in a very heavy UI.
Given that using CALayers
where ever possible over UIView
's are always lighter in weight, I am wondering if I convert the UIImageView
to CALayer
and setting UIImage
to setting content of CALayer
?
Current
//Every 2 seconds
myImageView.image = UIImage(cgImage: myCGImage)
Suggestion
//Every 2 seconds
myLayer.content = myCGImage
Since UIImageView
acts slightly different, I am wondering which method would be more efficient on the CPU/GPU overall.
Upvotes: 1
Views: 533
Reputation: 131398
In general, UIView
objects are fairly thin wrappers around CALayers
. UIImageView
is no exception to that. Most of the "heavy lifting" of decoding and displaying the image is done by the CALayer
in both cases, so I doubt if you'll see much difference.
UIImageView
is easier to use, and the resulting code is easier to read, so unless you need to do something that requires you to use CALayers
, I'd stick with UIKit
objects.
Upvotes: 3