实战需求
SwiftUI SafariServices 调用Safari浏览器组件
实战代码
import SwiftUI
import SafariServices
// 调用方式
.onTapGesture {
isShowingSheet.toggle()
}
.sheet(isPresented: $isShowingSheet) {
SFSafariView(url: articles.url)
}
//定义
struct SFSafariView: UIViewControllerRepresentable {
typealias UIViewControllerType = SFSafariViewController
let url: URL
func makeUIViewController(context: Context) -> SFSafariViewController {
let vc = SFSafariViewController(url: url)
return vc
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
}
}
加入我们一起学习SwiftUI
QQ:3365059189
SwiftUI技术交流QQ群:518696470
教程网站:www.openswiftui.com