美文网首页
SwiftUI 与 UIKit框架的交互

SwiftUI 与 UIKit框架的交互

作者: 小凡凡520 | 来源:发表于2019-10-18 16:46 被阅读0次
    MapView
    struct MapView: UIViewRepresentable {
        
        func makeUIView(context: Context) -> MKMapView {
            MKMapView(frame: CGRect.zero)
        }
        
        func updateUIView(_ uiView: MKMapView, context: Context) {
            let coordinate = CLLocationCoordinate2D(
              latitude: 34.011286, 
              longitude: 116.166868
            )
            let span = MKCoordinateSpan(latitudeDelta: 2, longitudeDelta: 2)
            let region = MKCoordinateRegion(center: coordinate, span: span)
            uiView.setRegion(region, animated: true)
        }
    }
    
    struct MapView_Preview: PreviewProvider {
        static var previews: some View {
            MapView()
        }
    }
    

    相关文章

      网友评论

          本文标题:SwiftUI 与 UIKit框架的交互

          本文链接:https://www.haomeiwen.com/subject/hxqwmctx.html