Skip to content

Instantly share code, notes, and snippets.

@tonisuter
Created September 21, 2015 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonisuter/35e43d2c7e77a1f67f20 to your computer and use it in GitHub Desktop.
Save tonisuter/35e43d2c7e77a1f67f20 to your computer and use it in GitHub Desktop.
import UIKit
import CoreMotion
class ViewController: UIViewController {
let motionManager = CMMotionManager()
var currentAngle:Double!
override func viewDidLoad() {
super.viewDidLoad()
motionManager.deviceMotionUpdateInterval = 0.1
motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.currentQueue()!) { (motion, error) in
if let attitude = motion?.attitude {
let interfaceOrientation = UIApplication.sharedApplication().statusBarOrientation
if UIInterfaceOrientationIsPortrait(interfaceOrientation) {
self.currentAngle = self.radiansToDegrees(attitude.pitch)
} else {
self.currentAngle = // TODO
}
}
//TODO: Update Label that shows the current angle
}
}
private func radiansToDegrees(radians: Double) -> Double {
return radians * 180 / M_PI
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment