在iOS 13之后,在pdf上导航文本框不再起作用-使用PDFKIT出现手势问题 [英] Navigating Text box on a pdf is not working any more after iOS 13 - seems gestures issue using PDFKIT

查看:78
本文介绍了在iOS 13之后,在pdf上导航文本框不再起作用-使用PDFKIT出现手势问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个项目,我使用PDFKIT做了一些如何在pdf上添加浮动文本框的操作,并且它可以通过用户使用 GestureRecognizer 在屏幕上触摸来移动并放置到用户决定的位置来进行导航.它在iOS 13之前运行良好,但是在iOS 13之后,它没有给您移动文本框的机会,我尝试了多种方法来解决它,但都失败了.

I implemented a project I used PDFKIT to do some how adding a floating Textbox on a pdf and it can navigate by users touch on screen using GestureRecognizer to move and put where users decide to. it has worked perfectly before iOS 13, but after it, it does not give you the chance to move the text box and I tried many ways to solve it but all failed.

看来问题出在某种程度上与 GestureRecognizer 有关,但我不确定,而且我真的不知道如何解决.我在github https://github.com/kishikawakatsumi/BookReader 上从事此项目,并试图扩展它的方式.

It seems that the problem somehow relates to GestureRecognizer but I am not sure, and also I really do not know how to fix it. I was working on this project on github https://github.com/kishikawakatsumi/BookReader and tried to expand it some how.

这是我的代码项目,我要插入整个函数,我知道这似乎有点复杂.对此深表歉意.但是,如果您认为它可能来自手势识别器,则只需查看属于这些功能的代码即可.

and here is my codes project, I am inserting the whole functions, I know it seems a little complicated. Really sorry about this. But if you think it might be from gesture recogniser, just look at the codes belong to these functions.

   func getPDFFrame(todo: String)

    {
      let pdfSubVws = pdfView.subviews
       print("subVws  ",pdfSubVws)
  for subVws in pdfSubVws

        {

            if (String(describing: subVws).range(of:"UIPageViewControllerContentView") != nil)

            {

                let pageVc = subVws.subviews



                for subVws in pageVc

                {

                    if (String(describing: subVws).range(of:"UIQueuingScrollView") != nil)

                    {

                        let QueueVc = subVws.subviews

                        //                        print("QueueVcQueueVc  ", QueueVc)

                        for subVws in QueueVc

                        {

                            if (String(describing: subVws).range(of:"UIView") != nil)

                            {

                                let viewVc = subVws.subviews

                                print("\n\nviewVcVcQueueVc  ", viewVc) //viewVcVcQueueVc   []



                                for subVws in viewVc

                                {

                                    if (String(describing: subVws).range(of:"UIView") != nil)

                                    {



                                        let SubviewVc = subVws.subviews

                                        //                                        print("\n\nSubviewVcSubviewVc  ", SubviewVc)



                                        for subVws in SubviewVc

                                        {

                                            if (String(describing: subVws).range(of:"UIScrollView") != nil)

                                            {

                                                let finalVw = subVws.subviews

                                                //                                                print("\n\nfinalVw  ", finalVw)

                                                //

                                                for subVws in finalVw

                                                {

                                                    if (String(describing: subVws).range(of:"UIView") != nil)

                                                    {

                                                        //                                                        print("subVwssubVws  ", subVws)



                                                        let pagView = subVws.subviews

                                                        //                                                        pdfLandingView =

                                                        for subVws in pagView

                                                        {

                                                            //                                                            print("\n\n EndVwssubVws  ", subVws)



                                                            if (String(describing: subVws).range(of:"PDFPageView") != nil)

                                                            {

                                                                let pageLandVw = subVws.subviews



                                                                print("\n\n WasVwssubVws  ", pageLandVw)



                                                                //  hideBars()

                                                                //  Myedit()







                                                                for subVws in pageLandVw

                                                                {

                                                                    if (String(describing: subVws).range(of:"UITextView") != nil)

                                                                    {

                                                                        print("dddddddd")



                                                                        let txtVw = subVws as! UITextView



                                                                        if todo == "firstResponder"

                                                                        {

                                                                            let rect = pdfView.currentPage?.bounds(for: .mediaBox)



                                                                            usingHeightText = txtVw.frame.size.height

                                                                            usingWidthText = txtVw.frame.size.width



                                                                            let xPoint = txtVw.frame.origin.x

                                                                            let yPoint = (rect?.height)! - (txtVw.frame.origin.y) - txtVw.frame.size.height





                                                                            lastTextAnnoPoint = CGPoint(x: xPoint, y: yPoint)



                                                                            findHavingTextAnnotation(annoPoint: CGPoint(x: xPoint, y: yPoint))



                                                                            //                                                                            txtVw.contentInset = UIEdgeInsetsMake(0, 10, 0, 0)



                                                                            print("C_Sz      ", txtVw.contentSize)

                                                                            print("C_Off      ", txtVw.contentOffset)



                                                                            let widthMoveView = UIView(frame: CGRect(x: txtVw.frame.size.width - 20, y: 0, width: 20, height: txtVw.frame.size.height))

                                                                            widthMoveView.backgroundColor = UIColor.brown.withAlphaComponent(0.0)

                                                                            widthMoveView.tag = 333





                                                                            let wdImgVw = UIImageView()

                                                                            wdImgVw.frame.origin.x = 0

                                                                            wdImgVw.frame.origin.y = 8

                                                                            wdImgVw.frame.size.width = 20 // widthMoveView.frame.width

                                                                            wdImgVw.frame.size.height = 20 // widthMoveView.frame.height

                                                                            wdImgVw.contentMode = .scaleAspectFit

                                                                            wdImgVw.image = UIImage(named: "widthLeftRight")



                                                                            wdImgVw.layer.cornerRadius = 10

                                                                            //                                                                            wdImgVw.backgroundColor = UIColor.orange



                                                                            widthMoveView.addSubview(wdImgVw)



                                                                            txtVw.addSubview(widthMoveView)

                                                                            //



                                                                            let tapVw = UIPanGestureRecognizer(target: self, action: #selector(self.handleWidthTapVw(_:)))

                                                                            widthMoveView.addGestureRecognizer(tapVw)





                                                                        }

                                                                        else
      //....and here I am going to omit the other parts of my codes

在这里,我将省略代码的其他部分,因为似乎在此行代码中出现了问题

and here I am going to omit the other parts of my codes because seems that the problem occurs in this line of code

for subVws in finalVw

以及我的代码的其他部分不确定您是否需要

and here other parts of my codes not sure you may need it or not

let linkAnn = PDFAnnotation.init(bounds: CGRect(x: 150, y: 450, width: 180, height: usingHeightText), forType: PDFAnnotationSubtype.widget, withProperties: nil)

        linkAnn.widgetFieldType = .text

        linkAnn.isMultiline = true

        linkAnn.contents = "fileNumber\(pdfClickedRow)PageNumber\(getPagenumber)addtext\(AddTextCount)"   //"\(AddTextCount)"

        linkAnn.widgetStringValue = NSLocalizedString("placeholder", comment: "")



        linkAnn.font = UIFont(name: usingFontName, size: CGFloat(usingFontSize))

        linkAnn.fontColor = usingFontColor

        linkAnn.backgroundColor = usingBGFontColor.withAlphaComponent(usingBGFontAlpha)

        linkAnn.setValue("addtext\(AddTextCount)", forAnnotationKey: PDFAnnotationKey.name)



      //  print("linkAnn.cont   ",linkAnn.contents)







        let index = pdfDocument?.index(for: pdfView.currentPage!)

        pdfView.document?.page(at: index!)?.addAnnotation(linkAnn)



        var createdColorDict = [String : Any]()

        createdColorDict["BGColor"] = usingBGFontColor

        createdColorDict["BGOpacity"] = usingBGFontAlpha



        textAnnoStoredDict["fileNumber\(pdfClickedRow)PageNumber\(getPagenumber)addtext\(AddTextCount)"] = createdColorDict





        //        pdfView.currentPage?.addAnnotation(linkAnn)

        bottomColorView.isHidden = true

        bottomColorView.backgroundColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)

        sideWidthHeightVw.backgroundColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 1.0)

        sideWidthHeightVw.isHidden = true

        barHideOnTapGestureRecognizer.isEnabled = false

        hideBars()





        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow),

                                               name: NSNotification.Name.UIKeyboardWillShow, object: nil)





        //keyboardWillShow

推荐答案

通过查看您的代码,我很难理解可能是什么问题.这是我的高级建议:1.首先备份您的代码,以确保可以恢复到稳定状态.2.开始将代码减半-每次消除一半逻辑路径.例如:与使用文本框的常规视图(而不是使用PDF视图)一起使用,而不是使用PDF视图.而不是使用UITextField,而仅使用UIView来查看UITextField是否存在问题.

Its hard for me to understand what could be the problem by looking at your code. Here's my high level suggestion: 1. Make a backup of your code first to make sure you can come back to your stable state. 2. Start cutting the code in half - eliminating half of the logic path each time. For example: Instead of using a PDF view, use a regular view with a text box (to find out if the problem is with the PDF view). Instead of using a UITextField, use just a UIView to see if it's a problem with UITextField.

基本上逐步消除所有的复杂性,直到您剩下一段简单的代码即可移动文本字段.

Basically remove all the complexity gradually until you are left with a simple piece of code that allows you to move the text field.

也:避免使用这么长的方法.我尝试将方法减少到最多30行,并且最多保留2个级别的嵌套.否则,您将拥有无法维护或理解的更多逻辑路径...

Also: avoid having such long methods. I try to keep methods down to 30 lines max, and 2 levels of nesting max. Otherwise you will have more logic paths than you can maintain or understand...

您还依赖于字符串作为对象类型.这是脆弱的.也许还有另一种方法来查找PDF视图,而不是对其进行整个视图层次结构的爬取并检查字符串?(它们未经编译器检查,因此将来的任何更改或OS/第三方版本之间的更改都将破坏您的代码).

You are also relying on strings for object types. This is fragile. Maybe there's another way to find the PDF View instead of crawling the whole view hierarchy for it, and checking strings? (They are not compiler checked, so any change in the future or change between OS / Third party versions will break your code).

如果您的文本字段完全不动,请尝试删除对框架所做的所有数学运算,然后使用手势识别器将其移动到任意坐标(例如:200、200),仅看看有什么东西将文本字段保持在适当的位置(如约束).您是否有可以承受的限制?使用视图检查器"检查并验证视图如何嵌入以及其上方/下方的内容.是否有任何东西可能会干扰您的手势识别器?它接收触摸并触发事件吗?您需要更准确地描述问题是什么...请在此处参考我的回答,以检查Gesture识别器本身. UIPanGestureRecognizer在iOS 13中无法正常工作

If your text field doesn't move at all, try to remove all that math you're doing with the frame, and just get it to move using gesture recognizer to any coordinate (for example: 200, 200), just to see that something is holding the text field in place (like a constraint). Do you have constraints that can be holding it? Use the "View Inspector" to check and verify how the view is embedded and what's above / below it. Is there anything that could be intercepting touches to your gesture recognizer? Is it receiving touches and firing it's event? You need to describe more exactly what the problem is... Please refer to my answer here for things to check on the Gesture recognizer itself. UIPanGestureRecognizer is not working in iOS 13

此PDF视图的视图层次结构是如此复杂,以至于很难说出其中的其他Touch事件可能发生的情况.(除非您确切了解第三方PDF View的工作原理).我将尝试找出问题所在,无论它是否与PDF视图相关.首先让它在常规视图中运行.然后使用hitTest处理PDF视图,并在其中放置打印语句,以查看谁在竞争HIT测试.

Your view hierarchy is so complex with this PDF view that it's hard to say what could be happening with other Touch events inside it . (unless you understand exactly how the third party PDF View works). I would try to isolate the problem, whether it's related to the PDF view or not. Get it working in just a regular View first. Then work on the PDF view by using hitTest, and put a print statement there, to see who is competing for the HIT test.

这篇关于在iOS 13之后,在pdf上导航文本框不再起作用-使用PDFKIT出现手势问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆