Skip to content

Instantly share code, notes, and snippets.

View brunomunizaf's full-sized avatar

Bruno Muniz brunomunizaf

View GitHub Profile
@brunomunizaf
brunomunizaf / AppDelegate.swift
Created February 11, 2018 20:58
Speeding up animations
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.keyWindow?.layer.speed = 100
return true
}
@brunomunizaf
brunomunizaf / ViewController.swift
Created August 15, 2018 14:03
Heartbeat AR/ML top final
import ARKit
import Vision
class ViewController: UIViewController {
@IBOutlet var sceneView: ARSCNView!
private let serialQueue = DispatchQueue(label: "com.hb.dispatchqueueml")
private var visionRequests = [VNRequest]()
private let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
}
@brunomunizaf
brunomunizaf / ViewController.swift
Last active August 21, 2018 14:31
UpdateCoreML()
// MARK: - Private
extension ViewController {
private func updateCoreML() {
let pixbuff : CVPixelBuffer? = (sceneView.session.currentFrame?.capturedImage)
if pixbuff == nil { return }
let ciImage = CIImage(cvPixelBuffer: pixbuff!)
let imageRequestHandler = VNImageRequestHandler(ciImage: ciImage, options: [:])
do {
@brunomunizaf
brunomunizaf / ViewController.swift
Last active August 21, 2018 20:51
Heartbeat AR/ML middle
// MARK: - Lifecycle
extension ViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupAR()
setupML()
loopCoreMLUpdate()
}
override func viewWillDisappear(_ animated: Bool) {
@brunomunizaf
brunomunizaf / ViewController.swift
Last active August 21, 2018 22:23
classificationCompleteHandler()
// MARK: - Private
extension ViewController {
private func classificationCompleteHandler(request: VNRequest, error: Error?) {
if error != nil {
print("Error: " + (error?.localizedDescription)!)
return
}
guard let observations = request.results else {
print("No results")
return
@brunomunizaf
brunomunizaf / ViewController.swift
Last active August 22, 2018 13:24
gesture recognizer
// MARK: - Private
extension ViewController {
@objc func tapped(recognizer: UIGestureRecognizer) {
guard let currentFrame = self.sceneView.session.currentFrame,
let url = URL(string: "https://www.supercharge.io") else {
return
}
webView.loadRequest(URLRequest(url: url))
enum State {
case initial
case final
}
protocol AnimatedTransition {
func imageView(for transition: TransitionDelegate) -> UIImageView?
}
class OtherViewController: UIViewController {
// MARK: - IBOutlets
@IBOutlet weak var imageView: UIImageView!
}
// MARK: - AnimatedTransition
extension OtherViewController: AnimatedTransition {
func imageView(for transition: TransitionDelegate) -> UIImageView? {
return imageView
}
extension TransitionDelegate: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if toVC is AnimatedTransition {
return self
}
return nil
@brunomunizaf
brunomunizaf / FirstScreen.swift
Last active June 6, 2019 01:47
AnimatedTransitioning
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(tappedImage))
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(tapRecognizer)
}