I want to program a simple Sprite Kit game in which I have to place some nodes randomly somewhere in the scene.
To ensure that these nodes are not placed outside the safe area I programmed this function:
func updatesafearea() {
let frame = self.size
let sets = view!.safeAreaInsets
let rect = CGRect(x: -(frame.width/2)-sets.left,
y: -(frame.height/2)-sets.top,
width: frame.width-sets.right-sets.left,
height: frame.height-sets.top-sets.bottom)
//Visualize the area
let node = SKShapeNode(rect: rect)
node.fillColor = .red
addChild(node)
}
This should be a rect in which all nodes should be presented safely, but unfortunately this doesn't work on iPhone X (Simulator):
iPhone 8 and iPhone X simulator screenshot below: