Swift PDF 查看器缩放?
Swift PDF viewer zoom?
我有一个 PDF 视图,但不确定如何解决缩放问题。当我希望它适合屏幕宽度时,它在 UI 上显示为大约 150% 缩放。没有对 UI 大小进行编辑可以修复缩放问题,因此必须在下面的结构中的某处修复它。感谢您的帮助!
struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL
init(_ url: URL) {
self.url = url
}
func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
let pdfView = PDFView()
pdfView.document = PDFDocument(url: self.url)
return pdfView
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
// Update the view.
}
}
struct PDFKitView: View {
var url: URL
var body: some View {
PDFKitRepresentedView(url)
}
}
PDFView
公开了一些不同的属性,您可以使用这些属性来改变它的显示方式。来自 PDFView
headers:
// -------- scaling
// Method to get / set the current scaling on the displayed PDF document. Default is 1.0 (actual size).
// Note that the given scaleFactor is clamped by the current min / max scale factors.
// When using a page view controller layout on iOS, this only affects the currently visible page and
// is ignored for any future loaded pages. You can observe the PDFViewPageChangedNotification notification
// to see when new pages are visible to apply new scale factors to them.
open var scaleFactor: CGFloat
// Set the minimum and maximum scaling factors for the PDF document. Assigning these values will implicitly turn
// off autoScales, and allows scaleFactor to vary between these min / max scale factors
@available(iOS 11.0, *)
open var minScaleFactor: CGFloat
@available(iOS 11.0, *)
open var maxScaleFactor: CGFloat
// Toggles mode whereby the scale factor is automatically changed as the view is resized, or rotated, to maximize the
// PDF displayed. For continuous modes this is a "fit width" behavior, for non-continuous modes it is a "best fit" behavior.
open var autoScales: Bool
我的第一个建议是尝试转动 on/off autoScales
(pdfView.autoScales = true
),看看这是否会改变您的感知。然后你也可以尝试手动设置 scaleFactor
我有一个 PDF 视图,但不确定如何解决缩放问题。当我希望它适合屏幕宽度时,它在 UI 上显示为大约 150% 缩放。没有对 UI 大小进行编辑可以修复缩放问题,因此必须在下面的结构中的某处修复它。感谢您的帮助!
struct PDFKitRepresentedView: UIViewRepresentable {
let url: URL
init(_ url: URL) {
self.url = url
}
func makeUIView(context: UIViewRepresentableContext<PDFKitRepresentedView>) -> PDFKitRepresentedView.UIViewType {
let pdfView = PDFView()
pdfView.document = PDFDocument(url: self.url)
return pdfView
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PDFKitRepresentedView>) {
// Update the view.
}
}
struct PDFKitView: View {
var url: URL
var body: some View {
PDFKitRepresentedView(url)
}
}
PDFView
公开了一些不同的属性,您可以使用这些属性来改变它的显示方式。来自 PDFView
headers:
// -------- scaling
// Method to get / set the current scaling on the displayed PDF document. Default is 1.0 (actual size).
// Note that the given scaleFactor is clamped by the current min / max scale factors.
// When using a page view controller layout on iOS, this only affects the currently visible page and
// is ignored for any future loaded pages. You can observe the PDFViewPageChangedNotification notification
// to see when new pages are visible to apply new scale factors to them.
open var scaleFactor: CGFloat
// Set the minimum and maximum scaling factors for the PDF document. Assigning these values will implicitly turn
// off autoScales, and allows scaleFactor to vary between these min / max scale factors
@available(iOS 11.0, *)
open var minScaleFactor: CGFloat
@available(iOS 11.0, *)
open var maxScaleFactor: CGFloat
// Toggles mode whereby the scale factor is automatically changed as the view is resized, or rotated, to maximize the
// PDF displayed. For continuous modes this is a "fit width" behavior, for non-continuous modes it is a "best fit" behavior.
open var autoScales: Bool
我的第一个建议是尝试转动 on/off autoScales
(pdfView.autoScales = true
),看看这是否会改变您的感知。然后你也可以尝试手动设置 scaleFactor