Created
September 21, 2015 12:54
-
-
Save tonisuter/35e43d2c7e77a1f67f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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