addSublayer vs addSubView which is more efficient?
- by soonio
I have 5 UIImageViews for displaying 5 images. For my app, I need swap the order of them depending on some events. I achieve this by calling:
[anImageView1 removeFromSuperview];
[self.view insertSubview:anImageView1 aboveSubview:anImageView2];
Recently, I've come across a different method for doing this using 1 UIView and 5 UIImageViews. Each layer of UIImageViews are added to this UIView by calling
[aView.layer addSublayer:anImageView1.layer];
[aView.layer addSublayer:anImageView2.layer];
etc.
and then in order to swap the order of things by calling
[anImageView1.layer removeFromSuperLayer];
[aView.layer insertSublayer:anImageView1 above: anImageView2]
Both methods work fine, but can someone please point out which method is better and why? I really can't seem to be able to find much on CALayer...
Please help! Thank you so much!