tbo
tbo

Reputation: 13

Delete _SCNSnapshotWindow after leaving Augmented Reality View

When leaving my Augmented Reality View Controller, there is these _SCNSnapshotWindow objects that still exists on the top left corner of my screen and prevent me from interacting with any objects beneath them, in my case its my return to main menu button. Anybody know how can I get rid of these objects?

View UI Hierarchy

Upvotes: 1

Views: 309

Answers (2)

RaulS
RaulS

Reputation: 99

I have faced the same issue today, and the way I solved is as following (yes, I have searched for the window by it's frame dimensions, don't judge me too hard on that :D ):

UIApplication.shared.windows.forEach {
        if $0.frame.width == 300 && $0.frame.height == 300 {
            print($0)
            $0.isHidden = true
        }
    }

I called it on my VC viewWillDisappear function, and it got rid of the problem. I'm sure it can be performed better, but I will have to look into it deeper then. Hope that helps you.

Upvotes: 2

toomanyredirects
toomanyredirects

Reputation: 2002

I had a similar problem when I was using an instance of UIView (in my case, subclassed) as the diffuse material contents on an SCNPlane within the scene.

Whilst UIView use as material contents is widely reported (here and elsewhere on the web) to work, it is notably absent from the official Apple documentation for the material contents

After reviewing the official documentation above I decided to switch to a documented (read: supported) method - in my case a UIImage - and the problem went away. That doesn't mean to say you can't continue to use a UIView, and maybe this is unique to the way I was doing it, but it's straightforward enough to turn the view into an image before assigning it as the material contents:

class MyCustomView: UIView {
    func renderAsImage() -> UIImage {
        let renderer = UIGraphicsImageRenderer(bounds: bounds)
        return renderer.image { context in
            layer.render(in: context.cgContext)
        }
    }
}

Then when setting the SCNPlane material contents, use:

if let view = UINib(nibName: "MyCustomView", bundle: nil).instantiate(withOwner: self, options: nil).first as? MyCustomView {
    plane.firstMaterial!.diffuse.contents = view.renderAsImage()
}

Upvotes: 2

Related Questions