【发布时间】:2019-06-04 17:09:11
【问题描述】:
我正在使用 ARKit 制作一个图像识别应用程序,用户将相机对准空间中的几个不同图像,视频将在这些图像上播放。我创建了带有消息的 UILabel,以便向用户提供说明。当用户第一次打开应用程序时,我想向他们显示一条消息,告诉他们将相机对准图像。每当相机跟踪图像时,我希望 UILabel 消失。
在我的代码中,我可以在跟踪图像时使标签消失的位置,但是一旦我不再跟踪图像,我就无法让它重新出现。
extension ViewController: ARSCNViewDelegate {
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor:
ARAnchor) -> SCNNode? {
let node = SCNNode()
//Show video overlayed to image
if let imageAnchor = anchor as? ARImageAnchor{
DispatchQueue.main.async { self.messageView?.isHidden =
true }
let plane = SCNPlane(width:
imageAnchor.referenceImage.physicalSize.width, height:
imageAnchor.referenceImage.physicalSize.height)
//Create Plane
switch imageAnchor.referenceImage.name!{
case "slaveAuction":
//Set AVPlayer as the planes texture and play
plane.firstMaterial?.diffuse.contents =
self.slaveAuction
self.slaveAuction.play()
case "columbus":
plane.firstMaterial?.diffuse.contents =
self.columbus
self.columbus.play()
case "isabellasCourt":
plane.firstMaterial?.diffuse.contents =
self.isabellasCourt
self.isabellasCourt.play()
case "hawksbell":
plane.firstMaterial?.diffuse.contents =
self.hawksbell
self.hawksbell.play()
default:
print("Images not found")
}
let planeNode = SCNNode(geometry: plane)
// Rotate the plane to match the anchor
planeNode.eulerAngles.x = -.pi/2
// Add plane node to parent
node.addChildNode(planeNode)
}
return node
}
}
当我不跟踪图像时,我需要帮助来显示消息视图。
【问题讨论】:
标签: swift uilabel augmented-reality arkit image-recognition