作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 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/
我是一名优秀的程序员,十分优秀!