我正在开发一款新的SwiftUI应用程序,我正在尝试找出如何使这个Swift项目与SwiftUI兼容:
https://github.com/suzuki-0000/SKPhotoBrowser
问题是我无法让UIViewRepresentable正常工作。我得到了一个错误:
“类型'PhotoViewer'不符合协议'UIViewRepresentable'”
以下是我的代码:
“类型'PhotoViewer'不符合协议'UIViewRepresentable'”
以下是我的代码:
struct PhotoViewer: UIViewRepresentable {
@Binding var viewerImages:[SKPhoto]
@Binding var currentPageIndex: Int
func makeUIView(context: Context) -> SKPhotoBrowser {
let browser = SKPhotoBrowser(photos: viewerImages)
browser.initializePageIndex(currentPageIndex)
browser.delegate = context.coordinator
return browser
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func updateUIView(_ browser: SKPhotoBrowser, context: Context) {
browser.photos = viewerImages
browser.currentPageIndex = currentPageIndex
}
class Coordinator: NSObject, SKPhotoBrowserDelegate {
var control: PhotoViewer
init(_ control: PhotoViewer) {
self.control = control
}
func didShowPhotoAtIndex(_ browser: PhotoViewer) {
self.control.currentPageIndex = browser.currentPageIndex
}
}
}
我这里错过了什么?