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 | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
NotificationCenter.default.addObserver(self, | |
selector: #selector(MainCameraVC.orientationChanged(notification:)), | |
name: Notification.Name.UIDeviceOrientationDidChange, |
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 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)? |
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 | |
class ViewController: UIViewController { | |
private var deviceOrientationHelper = DeviceOrientationHelper() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
deviceOrientationHelper.startDeviceOrientationNotifier { (deviceOrientation) in |