4

I have built an App an I'm about to finish my project.

And I need to put a imprint as a pdf-file in my App (legal reasons), which I thought would be no problem. But I can't figure out what I need to do to get a Close Button to just close the PDF File..

My code:

@IBAction func test(_ sender: Any) {

    let pdfView = PDFView()

    pdfView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(pdfView)

    pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
    pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
    pdfView.topAnchor.constraint(equalTo: view.topAnchor, constant:25).isActive = true
    pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true

    guard let path = Bundle.main.url(forResource: "ImpressumDatenschutz", withExtension: "pdf") else { return }

    if let document = PDFDocument(url: path) {
        pdfView.document = document
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Dogukan A
  • 83
  • 1
  • 10

3 Answers3

2

Create a floating button from Here and remove your pdfView by adding pdfView.removeFromSuperview() in the floating button action method.

Md Rais
  • 972
  • 1
  • 12
  • 21
1

I didn't find any other option than putting a button in the upper left corner with a segue that goes back to the page that was open before the PDF was opened. I guess that is good enough for the beginning.

@IBAction func backTapped(_ sender: Any) {
        performSegue(withIdentifier: "impressumToFirstVC", sender: self)        
    }
Dogukan A
  • 83
  • 1
  • 10
-1

Simple remove from its superview like below:

pdfView.removeFromSuperview()
Vetuka
  • 1,523
  • 1
  • 24
  • 40