eBay / HeadGazeLib
- вторник, 18 сентября 2018 г. в 00:17:19
Swift
A library to empower iOS app control through head gaze without a finger touch
HeadGazeLib is a pure Swift library to empower iOS app control through head gaze without a finger touch.
See the story behind it here

The above teaser is available at example/demo.
Any iOS developer who would like to introduce head-based control to their app. Ideal for accessibility and game control.
iPhone X, iOS 11, Swift 4
HeadGazeLib to your xcode project.UIHeadGazeViewController and change the button outlet reference class from UIButton to UIHoverableButton or UIBubbleButtonclass MyViewController: UIHeadGazeViewController{
@IBOutlet weak var myButton: UIBubbleButton! // UIButton!
}Similarily, change the button class from UIButton to UIHoverableButton or UIBubbleButton in the identity inspector of storyboard
Define head gaze event handler through UIHeadGazeRecognizer instance in MyViewController class
class MyViewController: UIHeadGazeViewController{
//.....
private var headGazeRecognizer: UIHeadGazeRecognizer? = nil
override func viewDidLoad() {
super.viewDidLoad()
setupGestureRecognizer()
}
private func setupGestureRecognizer() {
// set button dwell duration
self.myButton.dwellDuration = 1 // in second
// add head gaze recognizer to handle head gaze event
self.headGazeRecognizer = UIHeadGazeRecognizer()
//Between [0,9]. Stablize the cursor reducing the wiggling noise.
//The higher the value the more smoothly the cursor moves.
super.virtualCursorView?.smoothness = 9
super.virtualCursorView?.addGestureRecognizer(headGazeRecognizer)
self.headGazeRecognizer?.move = { [weak self] gaze in
self?.buttonAction(button: (self?.myButton)!, gaze: gaze)
}
}
private func buttonAction(button: UIButton, gaze: UIHeadGaze){
guard let button = button as? UIHoverableButton else { return }
// The button instance would trigger TouchUpInside event after user specified seconds
button.hover(gaze: gaze)
}
@IBAction func myBtnTouchUpInside(_ sender: UIBubbleButton) {
print("Button clicked by head gaze.")
}
//....
}For working demo, we have prepared three examples:
UIMultiFuncButton to track the location and timestamp of the cursor as user is "clicking" the button. Useful for sensitivity analysis.Copyright 2018 eBay Inc.
HeadGazeLib is available under the MIT license. See the LICENSE file for more info.
Jinrong Xie, Muratcan Cicek, Robinson Piramuthu