Skip to content

Instantly share code, notes, and snippets.

@PabloDomine
Created July 31, 2017 19:08
Show Gist options
  • Save PabloDomine/6f09484670225d8adbd5c7e7f58db822 to your computer and use it in GitHub Desktop.
Save PabloDomine/6f09484670225d8adbd5c7e7f58db822 to your computer and use it in GitHub Desktop.
Using my own class DeviceOrientationHelper to determine device orientation based on accelerometer motion data readouts
import UIKit
class ViewController: UIViewController {
private var deviceOrientationHelper = DeviceOrientationHelper()
override func viewDidLoad() {
super.viewDidLoad()
deviceOrientationHelper.startDeviceOrientationNotifier { (deviceOrientation) in
self.orientationChanged(deviceOrientation: deviceOrientation)
}
}
override func viewDidDisappear(_ animated: Bool) {
deviceOrientationHelper.stopDeviceOrientationNotifier()
super.viewDidDisappear(animated)
}
private func orientationChanged(deviceOrientation: UIDeviceOrientation) {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment