Skip to content

Instantly share code, notes, and snippets.

View PabloDomine's full-sized avatar

Pablo Dominé PabloDomine

  • Wallapop
  • Barcelona, Spain
View GitHub Profile
@PabloDomine
PabloDomine / ViewController.swift
Created July 31, 2017 19:08
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
@PabloDomine
PabloDomine / DeviceOrientationHelper.swift
Last active August 5, 2022 06:41
Class that determines Device Orientation based on the accelerometer motion data readouts
import Foundation
import CoreMotion
class DeviceOrientationHelper {
static let shared = DeviceOrientationHelper() // Singleton is recommended because an app should create only a single instance of the CMMotionManager class.
private let motionManager: CMMotionManager
private let queue: OperationQueue
typealias DeviceOrientationHandler = ((_ deviceOrientation: UIDeviceOrientation) -> Void)?
@PabloDomine
PabloDomine / ViewController.swift
Last active July 31, 2017 19:03
Subscribe to NotificationCenter's UIDeviceOrientationDidChange to know when to rotate the UI elements
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(MainCameraVC.orientationChanged(notification:)),
name: Notification.Name.UIDeviceOrientationDidChange,
import UIKit
@IBDesignable
class RoundedButton: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}