I'm having fun with SwiftUI's new MapKit capabilities, and I love how simple a LookAroundPreview
is to create. But the documentation claims that there is a
.lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene)
method that can be applied to existing views, and... well, it's not there - at least the compiler doesn't think so. To be clear, the documentation says:
To display a Look Around viewer a person can explore, apply a lookAroundViewer view modifier to a specific view, then add a control the user interacts with to display the Look Around viewer. In the following example, the lookAroundViewer view modifier observes a binding to Boolean value to determine whether to display the Look Around viewer.
Now, I have a static LookAroundPreview
working (and man that's great, for so little effort), but I think the documentation is a little ahead of itself...
My question is "has .lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene)
actually been implemented in Xcode 15b3, and if so, how do I invoke it?".
Many thanks. Here's the working code...
@State private var lookAroundScene: MKLookAroundScene?
@State private var isLookingAround = false
var body: some View {
VStack {
item.image
.resizable()
.aspectRatio(contentMode: .fill)
//.lookAroundViewer(isPresented: $isLookingAround, initialScene: lookAroundScene) //<--- DOESN'T WORK
if lookAroundScene.exists {
Button(systemImage: "binoculars") { isLookingAround = true }
}
}
.onAppear(perform: getLookAroundScene)
.popover(isPresented: $isLookingAround) {
LookAroundPreview(initialScene: lookAroundScene)
}
}
private func getLookAroundScene() {
lookAroundScene = nil
Task {
let request = MKLookAroundSceneRequest(coordinate: item.coordinate)
lookAroundScene = try? await request.scene
}
}
This seems to work now.
.lookAroundViewer
line is uncommented, the view becomes fullscreen after touching. If you comment the second LookaroundPreview
, the first one seems to miss an important initialization and the fullscreen preview appears but is empty.Full code: https://gist.github.com/thadk/ea2e067b246b3bf7d96b94115da1f846
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With