【问题标题】:Take screenshot of ARKit view截取 ARKit 视图
【发布时间】:2018-01-21 19:59:51
【问题描述】:

我将如何插入一个按钮并使用它来拍摄照片并将其放入照片库中。我注意到在使用 arkit 时我无法拖动按钮并将它们放在视图上。我在网上看到有人说你使用 snapshot() 来拍照。

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 
   }
}

【问题讨论】:

    标签: swift button swift4 photo arkit


    【解决方案1】:

    我做了一个简单的演示,向您展示如何组合snapshot()ARSCNViewUIBUtton。所以你可以这样定义你的故事板:

    如您所见,按钮位于主视图内部,但位于 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()
        }
    }
    

    最终结果是:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 2017-05-05
      • 2019-06-19
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多