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
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) |
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
// | |
// RightLeftTableViewCell.swift | |
// TableViewCellsSwipeStuff | |
// | |
// Created by Paul Wallace on 2/26/18. | |
// Copyright © 2018 Paul Wallace. All rights reserved. | |
// | |
import UIKit |
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
func createThumbnailOfVideoFromRemoteUrl(url: String) -> UIImage? { | |
let asset = AVAsset(url: URL(string: url)!) | |
let assetImgGenerate = AVAssetImageGenerator(asset: asset) | |
assetImgGenerate.appliesPreferredTrackTransform = true | |
//Can set this to improve performance if target size is known before hand | |
//assetImgGenerate.maximumSize = CGSize(width,height) | |
let time = CMTimeMakeWithSeconds(1.0, 600) | |
do { | |
let img = try assetImgGenerate.copyCGImage(at: time, actualTime: nil) | |
let thumbnail = UIImage(cgImage: img) |
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
//In our viewWillAppear configure the session to run with these settings | |
override func viewWillAppear(_ animated: Bool) { | |
//Standard tracking configuration | |
let configuration = ARWorldTrackingConfiguration() | |
//We want to detect all horizontal planes (i.e. the floor) | |
configuration.planeDetection = .horizontal | |
//Set the delegate to be self so we can be updated when relevant things happen | |
session.delegate = self | |
//Run the session using this configuration (no options for this) | |
session.run(configuration, options: []) |
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
//After running the session we add a light node to help the scene look a little better | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
//Create light object | |
let light = SCNLight() | |
//Set type to be ambient | |
light.type = .ambient | |
//Create corresponding node for light so we can add this into the scene graph | |
let ambientLightNode = SCNNode() | |
//Set position (won't change over course of session run). Note that position doens't matter for ambient light. |
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
//Add the sofa to the plane if possible when the screen is tapped | |
@IBAction func screenTapped(_ sender: UITapGestureRecognizer) { | |
//Get the location of the tap on screen | |
let location = sender.location(in: sceneView) | |
//Make sure that we do the follow stuff on a background queue as to make sure not to block the main queue | |
DispatchQueue.global(qos: .background).async { | |
//Perform a hit test using the location of tap to see if it is on a plane | |
let results = self.sceneView.hitTest(location, types: ARHitTestResult.ResultType.existingPlane) | |
//If the hit test is successful then we can add our object to the plane | |
if let result = results.first { |
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
//Perform before we run the session | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
//Load the scene from art.scnassets folder (important to put your assets in this folder) | |
guard let scene = SCNScene(named: "art.scnassets/main.scn") else {return} | |
//Set the scene property of our ARSCNView to our custom scene | |
sceneView.scene = scene | |
} |