swiftobjective-cpdfpdftron

How to hide PDFTron popup in Objective C


enter image description here

I am trying to disable this feature in default PDFtron library.

I tried a lot and not at all disable this item. If anyone knows how to disable it.

Thanks in advance


Solution

  • You can control the behavior of the popup menu with the following PTToolManagerDelegate method: toolManager(_:, shouldShowMenu:, forAnnotation:, onPageNumber:). You would want to return false from the method to disable the menu from appearing.

    Note that if you are using a PTDocumentController to show the document, then you will need to create a subclass and override that method:

    class CustomDocumentController : PTDocumentController {
        
        override func toolManager(_ toolManager: PTToolManager,
                                  shouldShowMenu menuController: UIMenuController,
                                  forAnnotation annotation: PTAnnot?,
                                  onPageNumber pageNumber: UInt) -> Bool {
            // Uncomment to disable popup menu in all scenarios.
            // return false
            
            if annotation == nil {
                // No annotation is selected.
                if toolManager.tool as? PTPanTool != nil {
                    // This is the long-press menu over blank space in the document.
                    
                    // Uncomment to disable long-press menu.
                    // return false
                } else if toolManager.tool as? PTTextSelectTool != nil {
                    // This is the text-selection menu shown for selected text.
                    
                    // Disable text-selection menu.
                    return false
                }
            }
            
            // Use default menu behavior from superclass.
            return super.toolManager(toolManager,
                                     shouldShowMenu: menuController,
                                     forAnnotation: annotation,
                                     onPageNumber: pageNumber)
        }
        
    }
    

    The code above will disable the text-selection menu, but leave the long-press (over blank space) and annotation-selection menus enabled. You can uncomment the commented-out lines to control those menus as well if you want.