Why is arView = ARView(frame: .zero) set to zero?

Hello,


Question:

In the default template for Augmented Reality App, if you set content technology to "RealityKit" and User Interface "SwiftUI", why is arView "frame" parameter set to ".zero"?


arView = ARView(frame: .zero)


My understanding of the line of code would be: Creates an AR view with the frame of CGRect whose origin and size are both zero.

To me this mean the View has origin at (0,0) and the size is 0.


I suppect this has to do with SwiftUI parent (ContentView) view defining the view size and position for the child ARViewContainer? But am really taking a guess. I am confused and am asking for help and clarity from the Apple Developer Community.


Reference pages that I am specifically pointing to.

https://developer.apple.com/documentation/realitykit/arview/3243232-init

https://developer.apple.com/documentation/coregraphics/cgrect/1455437-zero


Smartdog

We all learn by sharing what we know

Answered by smartdog in 413830022

Maxxfrazer,


Thank you for taking the time to respond and impart some valuable information.

I have investigated further the question at hand:


Question:

In the default template for Augmented Reality App, if you set content technology to "RealityKit" and User Interface "SwiftUI", why is arView "frame" parameter set to ".zero"?


arView = ARView(frame: .zero)


I believe a person named "Asperi"

has a give an answer that desirve to be inspected, in my opinion:


Asperi states in this post

"The frame does not matter at UIView creation time (ie. in makeUIView), because constructed view will be resized according to final layout in container view and resulting frame will be passed in UIView.draw."


I'm inclined to mark this as the correct answer.


Maxxfrazer or anyone else think this may be the answer , please feel free to mark this as the answer.


Smartdog

We all learn by sharing what we know

I typically set the frame to zero when making UIKit apps too (non SwiftUI), and later set the frame like this:


self.arView.frame = self.view.bounds
self.arView.autoresizingMask = [.flexibleWidth, .flexibleHeight]


I'm not extremely knowledgeable about UIKit in general, but this works for me to make the view scale to fit the screen accordingly no matter the orientation.

Accepted Answer

Maxxfrazer,


Thank you for taking the time to respond and impart some valuable information.

I have investigated further the question at hand:


Question:

In the default template for Augmented Reality App, if you set content technology to "RealityKit" and User Interface "SwiftUI", why is arView "frame" parameter set to ".zero"?


arView = ARView(frame: .zero)


I believe a person named "Asperi"

has a give an answer that desirve to be inspected, in my opinion:


Asperi states in this post

"The frame does not matter at UIView creation time (ie. in makeUIView), because constructed view will be resized according to final layout in container view and resulting frame will be passed in UIView.draw."


I'm inclined to mark this as the correct answer.


Maxxfrazer or anyone else think this may be the answer , please feel free to mark this as the answer.


Smartdog

We all learn by sharing what we know

Why is arView = ARView(frame: .zero) set to zero?
 
 
Q