addSublayer vs addSubView which is more efficient?

Posted by soonio on Stack Overflow See other posts from Stack Overflow or by soonio
Published on 2010-05-12T18:27:00Z Indexed on 2010/05/13 22:54 UTC
Read the original article Hit count: 475

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about calayer