【发布时间】:2020-01-23 22:00:08
【问题描述】:
我一直在 Swift Playgrounds 上试验 ARKit。我已经编写了启动代码,但是当我运行它时,什么也没有发生。它不评估代码,而是显示显示代码中任何问题的弹出窗口。
我知道我使用的代码有效,因为我在运行旧版本 Swift Playgrounds 的 iPad 上使用了相同的代码,并且代码运行良好。这似乎是 Swift Playgrounds 3 或 Swift 5 的问题。
这是有趣的部分。当我删除运行ARWorldTrackingConfiguration 初始化程序的代码行以及使视图控制器成为会话和场景的委托的代码时,代码运行得很好。当我把它放回去时,它又犯了同样的错误。我不知道出了什么问题。
我在第 6 代 iPad 上运行 Swift Playgrounds 3.0。 Playground 使用 ARKit、UIKit、SceneKit 和 PlaygroundSupport。
最后,这里有一些代码。
// Code inside modules can be shared between pages and other source files.
import ARKit
import SceneKit
import UIKit
extension ARSCNView {
public func setup(){
antialiasingMode = .multisampling4X
automaticallyUpdatesLighting = false
preferredFramesPerSecond = 60
contentScaleFactor = 1.0
if let camera = pointOfView?.camera {
camera.wantsHDR = true
camera.wantsExposureAdaptation = true
camera.exposureOffset = -1
camera.minimumExposure = -1
camera.maximumExposure = 3
}
}
}
public class vc : UIViewController, ARSessionDelegate, ARSCNViewDelegate {
var arscn : ARSCNView!
var scene : SCNScene!
public override func loadView() {
arscn = ARSCNView(frame: CGRect(x: 0, y: 0, width: 768, height: 1024))
arscn.delegate = self
arscn.setup()
scene = SCNScene()
arscn.scene = scene
var config = ARWorldTrackingConfiguration()
config.planeDetection = .horizontal
arscn.session.delegate = self
self.view = arscn
arscn.session.run(configåå)
}
public func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
public func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
public func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
最后,请注意,我在 Playground 主页面中呈现实时视图,并将课程放入共享代码中。
【问题讨论】:
-
得到答案后纠正问题是非常糟糕的主意!
-
我把那部分去掉了
标签: swift ipad augmented-reality arkit swift-playground