ARKit显示损坏的UIWebView

问题描述 投票:0回答:1

我正在尝试使用ARImageTrackingConfiguration检测图像,当检测到图像时,将显示UIWebView而不是扫描的图像。我阅读了有关新的WBWebView的许多问题,但也无法正常工作。

似乎我没有在使用DispatchMain的问题,似乎不是从主线程更新UIWebView的问题。

关于一个相关主题(我使用的代码几乎是相同的),如果我尝试放置一个SKVideoNode而不是UIWebView,那么如果我设置plane.cornerRadius = 0.25,则视频播放时会出现超大的延迟,并且顶部会有一些大像素。

代码如下


func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }

        updateQueue.async {
            let physicalWidth = imageAnchor.referenceImage.physicalSize.width
            let physicalHeight = imageAnchor.referenceImage.physicalSize.height

            // Create a plane geometry to visualize the initial position of the detected image
            let mainPlane = SCNPlane(width: physicalWidth, height: physicalHeight)

            mainPlane.firstMaterial?.colorBufferWriteMask = .alpha

            // Create a SceneKit root node with the plane geometry to attach to the scene graph
            // This node will hold the virtual UI in place
            let mainNode = SCNNode(geometry: mainPlane)
            mainNode.eulerAngles.x = -.pi / 2
            mainNode.renderingOrder = -1
            mainNode.opacity = 1

            // Add the plane visualization to the scene
            node.addChildNode(mainNode)

            // Perform a quick animation to visualize the plane on which the image was detected.
            // We want to let our users know that the app is responding to the tracked image.
            self.highlightDetection(on: mainNode, width: physicalWidth, height: physicalHeight, completionHandler: {

            DispatchQueue.main.async {
            let request = URLRequest(url: URL(string: "https://www.facebook.com/")!)
            let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 400, height: 672))
            webView.loadRequest(request)

            let webViewPlane = SCNPlane(width: xOffset, height: xOffset * 1.4)
            webViewPlane.cornerRadius = 0.25

            let webViewNode = SCNNode(geometry: webViewPlane)
            webViewNode.geometry?.firstMaterial?.diffuse.contents = webView
            webViewNode.position.z -= 0.5
            webViewNode.opacity = 0

            rootNode.addChildNode(webViewNode)
            webViewNode.runAction(.sequence([
                .wait(duration: 3.0),
                .fadeOpacity(to: 1.0, duration: 1.5),
                .moveBy(x: xOffset * 1.1, y: 0, z: -0.05, duration: 1.5),
                .moveBy(x: 0, y: 0, z: -0.05, duration: 0.2)
                ])
            )
        }


            })
        }
    }


VIDEO VERSION

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }

        updateQueue.async {
            let physicalWidth = imageAnchor.referenceImage.physicalSize.width
            let physicalHeight = imageAnchor.referenceImage.physicalSize.height

            // Create a plane geometry to visualize the initial position of the detected image
            let mainPlane = SCNPlane(width: physicalWidth, height: physicalHeight)

            mainPlane.firstMaterial?.colorBufferWriteMask = .alpha

            // Create a SceneKit root node with the plane geometry to attach to the scene graph
            // This node will hold the virtual UI in place
            let mainNode = SCNNode(geometry: mainPlane)
            mainNode.eulerAngles.x = -.pi / 2
            mainNode.renderingOrder = -1
            mainNode.opacity = 1

            // Add the plane visualization to the scene
            node.addChildNode(mainNode)

            // Perform a quick animation to visualize the plane on which the image was detected.
            // We want to let our users know that the app is responding to the tracked image.
            self.highlightDetection(on: mainNode, width: physicalWidth, height: physicalHeight, completionHandler: {

                let size = imageAnchor.referenceImage.physicalSize

                var videoNode = SKVideoNode()

                switch imageAnchor.name {
                case "Elephant-PostCard":
                    videoNode = SKVideoNode(fileNamed: "Movies/cat.mp4")

                case "puppy":
                    videoNode = SKVideoNode(fileNamed: "puppy.mov")
                default:
                    break
                }
                // invert our video so it does not look upside down
                videoNode.yScale = -1.0

                videoNode.play()

                let videoScene = SKScene(size: CGSize(width: 1280, height: 720))

                videoScene.anchorPoint = CGPoint(x: 0.5, y: 0.5)
                videoScene.addChild(videoNode)

                let plane = SCNPlane(width: size.width, height: size.height)
                plane.cornerRadius = 0.25
                plane.firstMaterial?.diffuse.contents = videoScene

                let planeNode = SCNNode(geometry: plane)
                plane.firstMaterial?.isDoubleSided = true

                mainNode.addChildNode(planeNode)

            })
        }
    }



ios swift uiwebview arkit
1个回答
0
投票

UIWebView模块中的[UIKit)现在已弃用。

© www.soinside.com 2019 - 2024. All rights reserved.