如何插入按钮并使用它拍摄照片并将其放入照片库。我注意到在使用arkit时我无法拖动按钮并将它们放在视图上。我看到网上有人说你用快照()来拍照。
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
// Create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// Set the scene to the view
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
// Run the view's session
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
答案 0 :(得分:0)
我做了一个简单的演示,向您展示如何合并snapshot()
,ARSCNView
和UIBUtton
。因此,您可以通过以下方式定义故事板:
如您所见,该按钮位于主视图内,但在ARKit视图的外部和上方
那么你的ViewController可能是这样的:
import UIKit
import ARKit
class ViewController: UIViewController {
@IBOutlet var arkitView:ARSCNView!
@IBOutlet var outputImageView:UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
arkitView.session.run(ARWorldTrackingConfiguration())
}
@IBAction func takeScreenshotAction() {
outputImageView.image = arkitView.snapshot()
}
}
最终结果是: