I am working on a Swift 4, SceneKit 3D game. I set the background of the scene to a CAGradientLayer using:
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.view.bounds
gradientLayer.colors = [UIColor.white.cgColor, UIColor.init(red: 160/255, green: 235/255, blue: 232/255, alpha: 1).cgColor]
sceneView.scene?.background.contents = gradientLayer
It works fine on ONLY my phone. If I use another testing device the CAGradientLayer blocks the scene. If I set the sceneView's background as a UIColor, it works on all devices.
How can I fix this and why is this a problem?
EDIT: It looks like for some reason it might be adding the gradientLayer as a subLayer to UIView. Any way to fix this?
This is because of the way UIKit renders views and layers. Make it as an image then set it as your background.