London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
19 C
New York
Sunday, October 20, 2024

ios – SwiftUI ARView unable to regulate dimension and alignment


I wish to have an ARView however solely partial show on the center of iPhone, so I created some code under

that is the container of ARView

struct ARViewContainer : UIViewRepresentable {
    var arViewModel: ARViewModel
    
    func makeUIView(context: Context) -> MyARView {
        arViewModel.startSessionDelegate()
        return arViewModel.arView
    }
    
    func updateUIView(_ uiView: MyARView, context: Context) {}
}

that is the ARViewModel

struct ARModel {
    personal(set) var arView : ARView
    
    init() {
        let rect = UIScreen.major.bounds
        let frameRect = CGRect(x: rect.minX, y: rect.minY, width: rect.width, peak: rect.peak/4)
        print(frameRect)

        arView = ARView(body: frameRect)

        let config = ARWorldTrackingConfiguration()
        config.planeDetection = [.horizontal]
        arView.session.run(config)
    }
}

class ARViewModel: UIViewController, ObservableObject, ARSessionDelegate {
    @Printed personal var mannequin : ARModel = ARModel()
    @Printed var mapImage: UIImage?
    
    var arView : MyARView {
        mannequin.arView
    }

    func startSessionDelegate() {
        mannequin.arView.session.delegate = self
    }
  
    func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {}

    func session(_ session: ARSession, didUpdate body: ARFrame) {
        if let picture = UIImage(pixelBuffer: body.capturedImage) {
            mapImage = LocSystem.rotateImage(picture)
        }    
    }  
}

that is the ContentView

struct ContentView: View {
    @ObservedObject var arViewModel : ARViewModel = ARViewModel()

    @State var mapImage: UIImage?

    var physique: some View {
        
        ZStack {
            if let picture = arViewModel.mapImage {
                Picture(uiImage: picture)
                    .resizable()
                    .scaledToFit()
                    .body(maxWidth: .infinity, maxHeight: .infinity)
                    .border(Coloration.pink)
                    .background(Coloration.cyan)
            } else {
                Coloration.grey
                    .ignoresSafeArea()
                ProgressView()
            }

            ARViewContainer(arViewModel: arViewModel)
                .scaledToFill()
                .body(maxWidth: .infinity)
                .body(peak: UIScreen.major.bounds.peak / 4, alignment: .high)
                .border(Coloration.blue)
                .cornerRadius(15)
                .padding(25)
       
                Spacer()
        }.navigationBarBackButtonHidden(true)
    }
}

Ultimately, the consequence seems like this
screenshot

The background is the ARView captured picture, The center body(ARView) is small however the image is aligned middle. I wish to align it .high. I can not change its crop dimension, alignment and so. Looks like ARView is so cussed. Why? Please assist

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com