Last active
August 17, 2017 20:09
-
-
Save kravik/f2b1094de81f3e6bc2282959c0faf264 to your computer and use it in GitHub Desktop.
arkit_session_tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
class ViewController: UIViewController, ARSCNViewDelegate { | |
lazy var sceneView: ARSCNView = { | |
let view = ARSCNView(frame: CGRect.zero) | |
view.delegate = self | |
return view | |
}() | |
//2 | |
lazy var infoLabel: UILabel = { | |
let label = UILabel(frame: CGRect.zero) | |
label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.title1) | |
label.textAlignment = .center | |
label.backgroundColor = .white | |
return label | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(sceneView) | |
//3 | |
view.addSubview(infoLabel) | |
} | |
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
sceneView.frame = view.bounds | |
//4 | |
infoLabel.frame = CGRect(x: 0, y: 16, width: view.bounds.width, height: 64) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
let configuration = ARWorldTrackingConfiguration() | |
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors]) | |
} | |
// MARK: ARSCNViewDelegate | |
func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera) { | |
//5 | |
var status = "Loading..." | |
switch camera.trackingState { | |
case ARCamera.TrackingState.notAvailable: | |
status = "Not available" | |
case ARCamera.TrackingState.limited(_): | |
status = "Analyzing..." | |
case ARCamera.TrackingState.normal: | |
status = "Ready" | |
} | |
infoLabel.text = status | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment