Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

ios - Subclassing QLPreviewController inside a UITabBarController does not show edit option of PDF

I am trying to present QLPreviewController as one of the Tab in a Tabview contorller. It able to show PDF properly but pencilkit/Markup not shown Reason: i want to show PencilKit to draw on the PDF and save it (other type of files from local or network also hence QL), also capture highlights from PDF(others)

Xcode 12.3 Swift 5 iOS/iPAD: 14

problem: Q1) Unable to view Markup or edit button at the stop of PDF files. Tried hiding tab bar and subviews are always nil. Any help is appreciated.

Q2) Is it possible to override Highlight sector/function in menuItem (on PDF i see nice options so want to use it however want to save the text selection)?

 class QLPreviewController2: QLPreviewController {
    var toolbars: [UIView] = []
    var observations : [NSKeyValueObservation] = []
   override func viewDidLoad() {
       super.viewDidLoad()
    delegate = self
   }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
    }
}

extension QLPreviewController2: QLPreviewControllerDelegate {
    
      func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode {
        return .updateContents
      }
        func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool {
            return true
        }
      func previewController(_ controller: QLPreviewController, didUpdateContentsOf previewItem: QLPreviewItem) {
      }
   
    func previewController(_: QLPreviewController, didSaveEditedCopyOf: QLPreviewItem, at: URL) {
    }
}

And my TabVC is

class TabVC: UITabBarController, UITabBarControllerDelegate  {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
        guard let viewcontollers = viewControllers else {
            return
        }
        let item1 = QLPreviewController2()
        item1.dataSource = self
//        self.navigationItem.rightBarButtonItems?.append(item1.editButtonItem) //did not work
        item1.isEditing = true //did not work
        item1.setEditing(true, animated: true)//did not work
            let icon1 = UITabBarItem(title: "Title", image: UIImage(named: "doc"), selectedImage: UIImage(named: "doc"))
            item1.tabBarItem = icon1
        self.viewControllers!.append(item1)
//        navigationItem.leftBarButtonItems?.append(item1.editButtonItem) //did not work
        }

        //Delegate methods
        func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
            print("Should select viewController: (viewController.title ?? "") ?")
            return true;
        }
    
}

extension TabVC: QLPreviewControllerDataSource {
    func numberOfPreviewItems(in: QLPreviewController) -> Int {
        return 1
    }
    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        print("2")
        let fileUrl = Bundle.main.url(forResource: "some", withExtension: ".pdf", subdirectory: nil, localization: nil)
        let filePreview = PreviewItem2()
        filePreview.previewItemURL = fileUrl
        return filePreview
    }
}
question from:https://stackoverflow.com/questions/65904977/subclassing-qlpreviewcontroller-inside-a-uitabbarcontroller-does-not-show-edit-o

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...