Thank you darkpaw, but I need this to work on an iMac as well as iOS devices, and "UIDevice" is part of "UIKit" which won't work on OSX. I think I need a SwiftUI solution.
I tried this and I think I nearly understood it. In the XCode preview, it worked perfectly but when I ran it in the "Simulator" (iPhone 11 and iPhone 15) I got the following runtime error:
SwiftUI/EnvironmentObject.swift:90: Fatal error: No ObservableObject of type OrientationInfo found. A View.environmentObject(_:) for OrientationInfo may be missing as an ancestor of this view.
This seems to be referring to the line "Text("Orientation is ...."
an
@BabyJ
That worked thank you so much. But now whenever I try to pick up the value envOrient.myOrient in the ContentView the App Crashes. What am I doing wrong now:
I was just trying to use a background image and get it to fit when the user rotates the device. But I have been at it for over a week now, and I can't get it to work, it is far too complicated, so I am just going to go with a plain white background. So thank you for all your help.
@AnnArborMark Thanks that seems to have done the job nicely, I have read and re-read the page you suggested, and I am still unsure what the "id:.self" does, but as it works I will just use it as you have suggested.
Thank you darkpaw, but I need this to work on an iMac as well as iOS devices, and "UIDevice" is part of "UIKit" which won't work on OSX. I think I need a SwiftUI solution.
I tried this and I think I nearly understood it. In the XCode preview, it worked perfectly but when I ran it in the "Simulator" (iPhone 11 and iPhone 15) I got the following runtime error:
SwiftUI/EnvironmentObject.swift:90: Fatal error: No ObservableObject of type OrientationInfo found. A View.environmentObject(_:) for OrientationInfo may be missing as an ancestor of this view.
This seems to be referring to the line "Text("Orientation is ...."
an
@BabyJ
That worked thank you so much. But now whenever I try to pick up the value envOrient.myOrient in the ContentView the App Crashes. What am I doing wrong now:
I was just trying to use a background image and get it to fit when the user rotates the device. But I have been at it for over a week now, and I can't get it to work, it is far too complicated, so I am just going to go with a plain white background. So thank you for all your help.
@AnnArborMark Thanks that seems to have done the job nicely, I have read and re-read the page you suggested, and I am still unsure what the "id:.self" does, but as it works I will just use it as you have suggested.