【发布时间】:2020-01-17 07:21:40
【问题描述】:
我正在尝试通过 UIViewControllerRepresentable 在 SwiftUI 中实现 unsplash-photopicker-ios 组件。视图启动成功,但是unsplashPhotoPicker函数不起作用,总是返回nil,谁能告诉我是什么问题。
import SwiftUI
import UnsplashPhotoPicker
struct UnsplashImagePicker: UIViewControllerRepresentable {
var urlUnsplashImage = [UnsplashPhoto]()
let configuration = UnsplashPhotoPickerConfiguration(
accessKey: "f99d21d6eb682196455dd29b621688aff2d525c7c3a7f95bfcb05d497f38f5dc",
secretKey: "ccff858162e795c062ce13e9d16a2cf607076d0eb185141e35b14f589b1cd713",
allowsMultipleSelection: false)
func makeUIViewController(context: UIViewControllerRepresentableContext<UnsplashImagePicker>) -> UnsplashPhotoPicker {
let unsplashImagePicker = UnsplashPhotoPicker(configuration: configuration)
unsplashImagePicker.delegate = context.coordinator
return unsplashImagePicker
}
func makeCoordinator() -> UnsplashImagePicker.Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, UnsplashPhotoPickerDelegate, UINavigationControllerDelegate {
var parent: UnsplashImagePicker
init(_ parent: UnsplashImagePicker) {
self.parent = parent
}
func unsplashPhotoPicker(_ photoPicker: UnsplashPhotoPicker, didSelectPhotos photos: [UnsplashPhoto]) {
print(photos)
}
func unsplashPhotoPickerDidCancel(_ photoPicker: UnsplashPhotoPicker) {
print("Unsplash photo picker did cancel")
}
}
func updateUIViewController(_ uiViewController: UnsplashPhotoPicker, context: UIViewControllerRepresentableContext<UnsplashImagePicker>) {
}
}
【问题讨论】:
标签: swift uiviewcontroller swiftui