I have the bellow line of code which is meant to prevent a problem where a sublayer is displayed over another posts content. The method in which this line is excited is called at the time of the user exiting a post.
newBaseP3FolderLayer.layer.sublayers?.remove(at: 1)
But now, I think as a result of this code, there are instances where another video will all of a sudden cover all other images.
I noticed that this only happens when the number of subLayers is 14. (This also may be true for numbers above this) while printing the number of sublayers when leaving a post I noticed that the code worked fine (for vals like 10 or 11 and 12) until the number of subviews went to 14.
How can I fix this?
This would be better approach
for sublayer in sublayers {
if sublayer.name == "yourLayerName" {
sublayer.removeFromSuperlayer()
}
}
Store the reference
to the layer
you want to remove while creating it and use that reference
to remove the layer
from its superLayer
, ie
var yourLayer: CALayer?
view.layer.sublayers?.forEach({ (layer) in
if layer == yourLayer {
yourLayer?.removeFromSuperlayer()
}
})
If you don't want to use layer names, try logging this:
NSLog(@"%@",self.playerLayer.player.currentItem.asset);
You will see the following:
AVURLAsset: 0x60000063bac0, URL = file:///Temp/Loops/088_JB_HD.mov
You can then identify the actual name and URL of your asset.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.