Swift: remove layer, without removing UIView in UITableViewCell
I found the problem. I made a simple mistake. I used self.layer.sublayers
, but I must use self.contentView.layer.sublayers
this is my mistake.
When I found that, I was able to fix another issues and use addLayer:below:
.
So, if you don't see a layer that must be in sublayer of your object, means that you're looking at the wrong place, think where it can be else and you'll find it, like in UITableView you need to work with contentView.
You can add myLayer
below UIView.layer
by setting
myLayer.zPosition = -1
The example below could have fixed your problem as well.
First solution:
self.avPlayerLayer.zPosition = 0 // or -1
self.view.layer.addSublayer(self.avPlayerLayer)
Or second solution
self.view.layer.insertSublayer(self.avPlayerLayer, below: self.button1.layer)