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
2.6 C
New York
Friday, January 31, 2025

ios – Lock orientation of a view to solely panorama


I’m making an attempt to current a view in panorama orientation from a portrait view utilizing the beneath code

   Button {
      isLandscapeViewPresented.toggle()
   } label: {
      Textual content("Click on for panorama view")
   }.fullScreenCover(isPresented: $isLandscapeViewPresented) {
     LandscapeOnlyView {
        LandscapeView()
     }
   }

And in LandscapeOnlyView wrapper I’ve as beneath

struct LandscapeOnlyView<Content material: View>: UIViewControllerRepresentable {
    
    let content material: Content material
    
    init(@ViewBuilder content material: () -> Content material) {
        self.content material = content material()
    }
    
    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
    
    
    func makeUIViewController(context: Context) -> some UIViewController {
        return LandscapeHostingController(rootView: content material)
    }
}

For LandscapeHostingController which holds the rootview as beneath:

class LandscapeHostingController<Content material: View>: UIHostingController<Content material> {
        
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .panorama
    }
        
    override func viewWillAppear(_ animated: Bool) {
        tremendous.viewWillAppear(animated)
        AppDelegate.orientationLock = .panorama
        let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
        scene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscapeRight), errorHandler: { error in
            print(error)
        })
    }
        
    override func viewWillDisappear(_ animated: Bool) {
        tremendous.viewWillDisappear(animated)
        
        AppDelegate.orientationLock = .portrait
        let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
        scene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait), errorHandler: { error in
            print(error)
        })
    }
}

I’m utilizing AppDelegate, as you possibly can see the place I replace the orientationLock, with supportedInterfaceOrientations override returning the up to date orientation each time I would like to vary orientations.

I get the beneath output.

Sample

I would like the LandscapeView to be in panorama even earlier than presenting not like what’s present above the place the view switches to panorama because the orientation replace is completed in viewWillAppear of the LandscapeHostingController wrapper for a swift ui view.

I’ve tried some ways. Is there one thing unsuitable in my method which ought to be modified.

Any concepts on how that or not it’s achieved?

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com