gpt4 book ai didi

ios - ARKit 显示损坏的 UIWebView

转载 作者:行者123 更新时间:2023-11-29 05:24:32 28 4
gpt4 key购买 nike

我正在尝试使用 ARImageTrackingConfiguration 检测图像,当检测到图像时,会显示 UIWebView 而不是扫描的图像。我读到了很多有关新 WBWebView 的问题,但也不起作用。

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

在一个相关主题上(我使用的代码几乎相同),如果我尝试放置 SKVideoNode 而不是 UIWebView,如果我设置plane.cornerRadius =,则视频播放时会出现 super 延迟,并且顶部有一些大像素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)

})
}
}



最佳答案

UIWebView UIKit 模块中的 现已弃用。

使用WKWebView来自 WebKit 模块。

关于ios - ARKit 显示损坏的 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58307562/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com