我已经使用MapKit实现了 Apple SwiftUI 教程的略微更改版本。
当我运行它时,我收到错误消息并调整我得到的相应视图的大小:
[SwiftUI] NSHostingView is being laid out reentrantly while rendering its SwiftUI content. This is not supported and the current layout pass will be skipped.
查看调用代码:
MapView(coordinate: location?.coordinates)
.frame(minHeight: 200)
.overlay(
GeometryReader{
proxy in
Button("Open in Maps") {
if (self.location?.coordinates != nil){
let destination = MKMapItem(placemark: MKPlacemark(coordinate: self.location!.coordinates))
destination.name = "the car"
destination.openInMaps()
}
}
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .bottomTrailing)
.offset(x: -10, y: -10)
}
)
Run Code Online (Sandbox Code Playgroud)
地图视图结构:
import SwiftUI
import MapKit
/// a …Run Code Online (Sandbox Code Playgroud)