0
votes

I want to change the frame of a SCNView at some point during the runtime. I have the SCNView initialized as below:

var sceneView: SCNView!

sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
let scene = SCNScene(named: "...")!
sceneView.scene = scene
sceneView.delegate = self
view.addSubview(sceneView)

However, I'm unable to change its frame with the following:

sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))

The sceneView simply remains the same size and position.

1

1 Answers

0
votes

Answer provided by Apple:

After the view is created and added a subview of another view, changing the sceneView instance variable doesn't change the view hierarchy. If a new view if instantiate the old one should be removed and the new one added to the parent view. Note that changing the frame does not require one to instantiate a new instance of the view (this is actually very costly and inefficient). The frame property of the view is mutable. Also note that auto layout and other technologies might be involved there.