Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FaceDetection.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@
TargetAttributes = {
80C316021A46F3F800E4493F = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 0820;
};
80C316171A46F3F800E4493F = {
CreatedOnToolsVersion = 6.2;
LastSwiftMigration = 0820;
TestTargetID = 80C316021A46F3F800E4493F;
};
};
Expand Down Expand Up @@ -347,6 +349,7 @@
INFOPLIST_FILE = FaceDetection/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -358,6 +361,7 @@
INFOPLIST_FILE = FaceDetection/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
Expand All @@ -377,6 +381,7 @@
INFOPLIST_FILE = FaceDetectionTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FaceDetection.app/FaceDetection";
};
name = Debug;
Expand All @@ -392,6 +397,7 @@
INFOPLIST_FILE = FaceDetectionTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FaceDetection.app/FaceDetection";
};
name = Release;
Expand Down
12 changes: 6 additions & 6 deletions FaceDetection/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var activeCornerRadius : CGFloat = 0
var incativeCornerRadius : CGFloat = 0

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window!.clipsToBounds = true

let animation : CABasicAnimation = CABasicAnimation(keyPath: "cornerRadius")
Expand All @@ -25,29 +25,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
animation.toValue = activeCornerRadius
animation.duration = 0.15
window!.layer.cornerRadius = activeCornerRadius
window!.layer.addAnimation(animation, forKey: "cornerRadius")
window!.layer.add(animation, forKey: "cornerRadius")

return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
let animation : CABasicAnimation = CABasicAnimation(keyPath: "cornerRadius")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
animation.fromValue = activeCornerRadius
animation.toValue = incativeCornerRadius
animation.duration = 0.15
window!.layer.cornerRadius = incativeCornerRadius
window!.layer.addAnimation(animation, forKey: "cornerRadius")
window!.layer.add(animation, forKey: "cornerRadius")
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
let animation : CABasicAnimation = CABasicAnimation(keyPath: "cornerRadius")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
animation.fromValue = incativeCornerRadius
animation.toValue = activeCornerRadius
animation.duration = 0.15
window!.layer.cornerRadius = activeCornerRadius
window!.layer.addAnimation(animation, forKey: "cornerRadius")
window!.layer.add(animation, forKey: "cornerRadius")
}
}

26 changes: 13 additions & 13 deletions FaceDetection/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import UIKit

class ViewController: UIViewController {

private var visage : Visage?
private let notificationCenter : NSNotificationCenter = NSNotificationCenter.defaultCenter()
fileprivate var visage : Visage?
fileprivate let notificationCenter : NotificationCenter = NotificationCenter.default

let emojiLabel : UILabel = UILabel(frame: UIScreen.mainScreen().bounds)
let emojiLabel : UILabel = UILabel(frame: UIScreen.main.bounds)

override func viewDidLoad() {
super.viewDidLoad()

//Setup "Visage" with a camera-position (iSight-Camera (Back), FaceTime-Camera (Front)) and an optimization mode for either better feature-recognition performance (HighPerformance) or better battery-life (BatteryLife)
visage = Visage(cameraPosition: Visage.CameraDevice.FaceTimeCamera, optimizeFor: Visage.DetectorAccuracy.HigherPerformance)
visage = Visage(cameraPosition: Visage.CameraDevice.faceTimeCamera, optimizeFor: Visage.DetectorAccuracy.higherPerformance)

//If you enable "onlyFireNotificationOnStatusChange" you won't get a continuous "stream" of notifications, but only one notification once the status changes.
visage!.onlyFireNotificatonOnStatusChange = false
Expand All @@ -32,19 +32,19 @@ class ViewController: UIViewController {
let cameraView = visage!.visageCameraView
self.view.addSubview(cameraView)

let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
visualEffectView.frame = self.view.bounds
self.view.addSubview(visualEffectView)

emojiLabel.text = "😐"
emojiLabel.font = UIFont.systemFontOfSize(50)
emojiLabel.textAlignment = .Center
emojiLabel.font = UIFont.systemFont(ofSize: 50)
emojiLabel.textAlignment = .center
self.view.addSubview(emojiLabel)

//Subscribing to the "visageFaceDetectedNotification" (for a list of all available notifications check out the "ReadMe" or switch to "Visage.swift") and reacting to it with a completionHandler. You can also use the other .addObserver-Methods to react to notifications.
NSNotificationCenter.defaultCenter().addObserverForName("visageFaceDetectedNotification", object: nil, queue: NSOperationQueue.mainQueue(), usingBlock: { notification in
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "visageFaceDetectedNotification"), object: nil, queue: OperationQueue.main, using: { notification in

UIView.animateWithDuration(0.5, animations: {
UIView.animate(withDuration: 0.5, animations: {
self.emojiLabel.alpha = 1
})

Expand All @@ -60,15 +60,15 @@ class ViewController: UIViewController {
})

//The same thing for the opposite, when no face is detected things are reset.
NSNotificationCenter.defaultCenter().addObserverForName("visageNoFaceDetectedNotification", object: nil, queue: NSOperationQueue.mainQueue(), usingBlock: { notification in
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "visageNoFaceDetectedNotification"), object: nil, queue: OperationQueue.main, using: { notification in

UIView.animateWithDuration(0.5, animations: {
UIView.animate(withDuration: 0.5, animations: {
self.emojiLabel.alpha = 0.25
})
})
}

override func prefersStatusBarHidden() -> Bool {
override var prefersStatusBarHidden : Bool {
return true
}
}
}
Loading