Created
November 22, 2019 04:54
-
-
Save quangDecember/54a86c8fd52bb41bb0f94730bb00657f to your computer and use it in GitHub Desktop.
Combine ObservableObject for SwiftUI to refresh with orientation
This file contains hidden or 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
@available(iOS 13.0, *) | |
class DeviceOrientationObservable : ObservableObject { | |
@Published var orientation = UIDevice.current.orientation | |
init () { | |
NotificationCenter.default.addObserver(self, selector: #selector(isRotated), name: UIDevice.orientationDidChangeNotification, object: nil) | |
} | |
@objc func isRotated() { | |
self.orientation = UIDevice.current.orientation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment