iOS device/interface/image/video orientation translation & detection using CoreMotion + SwiftUI + Combine.
MIT License
iOS device/interface/image/video orientation translation & detection using CoreMotion + SwiftUI + Combine.
@main
struct DemoApp: App {
var body: some Scene {
WindowGroup {
// Call `.withOrientations()` to start observing
// CoreMotion-based device orientation changes.
// This keeps notifying even when device orientation
// is locked.
ContentView()
.withOrientations()
}
}
}
struct ContentView: View {
@Environment(\.deviceOrientation)
private var deviceOrientation
@Environment(\.interfaceOrientation)
private var interfaceOrientation
/// - Note: To grab other `OrientationManager`'s properties
/// e.g. `deviceMotion`, just access via `@EnvironmentObject`.
@EnvironmentObject
private var manager: OrientationManager
var body: some View {
...
}
}
See Examples for more information.