Pedro J
Pedro J

Reputation: 311

any guess why I can't get arView's width and height...?

struct ARViewContainer:UIViewRepresentable{

func makeUIView(context: Context) ->  CustomARView {
    var arView = CustomARView(frame: .zero)
    arView.session.delegate = context.coordinator
    context.coordinator.view=arView
    context.coordinator.width = Int(arView.bounds.width)
    context.coordinator.height=Int(arView.bounds.height)
    wwidth=Int(arView.bounds.width)
    hheight=Int(arView.bounds.height)
    print("makeui \(arView.bounds.width)")

my code is...as above. I think it's simple but don't know why I can't get width and height of arview

Upvotes: 0

Views: 251

Answers (1)

Euan
Euan

Reputation: 618

You are retrieving the bounds of the arView, in which you have set its frame to .zero. Hence, the frame for arView is CGRect(x: 0, y: 0, width: 0, height: 0). You have set the context.coordinate size in the following lines:

context.coordinator.width = Int(arView.bounds.width)
context.coordinator.height=Int(arView.bounds.height)

...but this does not change the frame of the arView. To fix this, you need to set the width and height of the arView:

var arView = CustomARView(frame: CGRect(x: 0, y: 0, width: given_width, height: given_height))

Upvotes: 1

Related Questions