Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add CALayer below UIView

I got a UIView (let's call it superview) which contains another UIView (lets call it subview).

I'd like to add a CALayer so that it is visible on top of my superview, but under my subview. In other words, my subview's background should override the layer.

I've had a look at addLayer:below: and others, but I'm not sure how to use it. Thanks.

EDIT: My bad, I had another view between superview and subview, and I was messing with it. Thanks guys !

like image 412
DCMaxxx Avatar asked Nov 27 '13 13:11

DCMaxxx


People also ask

How do I add CALayer to view?

Your implementation of this method can do any of the following: - Adjust the size and position of any immediate subviews. - Add or remove subviews or Core Animation layers. - Force a subview to be redrawn by calling its setNeedsDisplay or setNeedsDisplayInRect: method.

What is the difference between UIView and CALayer?

Working with UIViews happens on the main thread, it means it is using CPU power. CALayer: Layers on other hand have simpler hierarchy. That means they are faster to resolve and quicker to draw on the screen. There is no responder chain overhead unlike with views.

What is the layer property on a UIView object?

All UIView subclasses have a layer property, which is responsible for drawing their contents efficiently. These layers are powered by Core Animation, which handles all the drawing and animation that UIKit requests.

What is CALayer?

An object that manages image-based content and allows you to perform animations on that content.


1 Answers

In Swift:

self.view.layer.insertSublayer(self.avPlayerLayer, below: self.button1.layer)
like image 152
King-Wizard Avatar answered Sep 21 '22 15:09

King-Wizard