Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created July 15, 2017 03:03
Show Gist options
  • Save staycreativedesign/f4f83cf18bf6e50520173d6eb548f45c to your computer and use it in GitHub Desktop.
Save staycreativedesign/f4f83cf18bf6e50520173d6eb548f45c to your computer and use it in GitHub Desktop.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(InformationController.counter), userInfo: nil, repeats: true)
questionArea.textColor = .white
let infoLayer = self.view.layer
infoLayer.cornerRadius = 20.0
infoLayer.borderWidth = 10.0
infoLayer.borderColor = UIColor.white.cgColor
let card = randomize(deck: selectedDeck)
questionArea.text = card.name
motionManager.gyroUpdateInterval = 0.1
motionManager.startGyroUpdates(to: OperationQueue.current!) { (data, error) in
if let myData = data {
let coordinates = myData.rotationRate.y
switch coordinates {
case let y where y < -5:
print("up")
print(coordinates)
self.motionManager.stopGyroUpdates()
// self.timer.invalidate()
self.performSegue(withIdentifier: "Orange", sender: nil)
self.selectedCards.append(Card(name: card.name, outcome: .wrong, alpha: 0))
case let y where y > 5:
print("down")
print(coordinates)
self.motionManager.stopGyroUpdates()
self.performSegue(withIdentifier: "Green", sender: nil)
// self.timer.invalidate()
self.selectedCards.append(Card(name: card.name, outcome: .right, alpha: 0))
default:
print(coordinates)
}
}
}
}
func counter() {
seconds -= 1
timerCountdown.text = String(seconds)
if (seconds == 0) {
timer.invalidate()
self.motionManager.stopGyroUpdates()
self.performSegue(withIdentifier: "tempoFinal", sender: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment