Quero criar um PDFView com PDFThumbnailView incorporado para macOS. O PDFThumbnailView deve estar vertical, no lado direito do PDFView. Desejo que ambas as visualizações estejam dentro de um NSViewRepresentable. No entanto, não estou muito familiarizado com o UIKit e suas restrições e o melhor que posso fazer é fazer com que o PDFThumbnailView se sobreponha ao PDFView. Como separar o PDFView e o PDFThumbnailView, para que não se sobreponham? Aqui está o código:
struct PDFViewWrapper: NSViewRepresentable {
let pdfView = PDFView()
@Binding var pdfDisplay: Int
func makeNSView(context: Context) -> PDFView {
let fileURL = FileManagerClient.shared.getDocumentsDirectory().appendingPathComponent("example.PDF")
let pdfDocument = PDFDocument(url: fileURL)
///
let thumbnailView = PDFThumbnailView()
thumbnailView.translatesAutoresizingMaskIntoConstraints = false
pdfView.addSubview(thumbnailView)
thumbnailView.pdfView = pdfView
NSLayoutConstraint.activate(
[
thumbnailView.leadingAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.leadingAnchor),
thumbnailView.topAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.topAnchor),
thumbnailView.bottomAnchor.constraint(equalTo: pdfView.safeAreaLayoutGuide.bottomAnchor),
thumbnailView.widthAnchor.constraint(equalToConstant: 80),
]
)
thumbnailView.thumbnailSize = CGSize(width: 100, height: 100)
thumbnailView.backgroundColor = .placeholderTextColor
///
pdfView.document = pdfDocument
pdfView.autoScales = true
pdfView.displayMode = PDFDisplayMode(rawValue: pdfDisplay) ?? .singlePageContinuous
return pdfView
}
func updateNSView(_ uiView: PDFView, context: Context) {}
}