gpt4 book ai didi

ios - "Cannot assign value of type ' 无效 ' to type ' PDFAction?为 PDFAnnotation 设置操作时出现 '"错误

转载 作者:行者123 更新时间:2023-11-28 13:53:21 25 4
gpt4 key购买 nike

在我的 PDF 查看器应用程序中,我成功打开了一个 PDF 并显示了它的所有内容。该应用程序将始终显示的 PDF 非常大,有 130 页。在 PDF 的第二页中,有一个目录。我想在文本中添加一个 PDFButton 并滚动到用户选择的 PDF 中的正确页面。

我当前的代码显示了一个按钮,但我希​​望该按钮执行的操作导致错误:

Cannot assign value of type 'Void' to type 'PDFAction?'

这是我试过的代码:

func insertResetButtonInto(_ page: PDFPage, GoTo: PDFPage) {
let resetButtonBounds = CGRect(x: 90, y: 200, width: 200, height: 15)
let resetButton = PDFAnnotation(bounds: resetButtonBounds, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
resetButton.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.button.rawValue)
resetButton.widgetControlType = .pushButtonControl
resetButton.backgroundColor = UIColor.green
page.addAnnotation(resetButton)

// Create PDFActionResetForm action to clear form fields.
resetButton.action = pdfView.go(to: page)
}

我如何在 PDF 中创建一个按钮,作为一个序列或滚动功能,将用户带到同一 PDF 文档中的不同页面?

最佳答案

您正在尝试将函数分配给需要 PDFAction 的变量。将引发错误的行替换为以下内容:

resetButton.action = PDFActionGoTo(destination: PDFDestination(page: page, at: .zero))

这会将带有您之前初始化的页面的 PDFDestination 传递给 PDFActionGoTo(destination:) 初始化器。

如果要修改目的地的点,请将PDFDestination 初始化器的at 参数更改为另一个CGPoint 值:

let point = CGPoint(x: 50, y: 100)
resetButton.action = PDFActionGoTo(destination: PDFDestination(page: page, at: point))

关于ios - "Cannot assign value of type ' 无效 ' to type ' PDFAction?为 PDFAnnotation 设置操作时出现 '"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54257007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com