0

I have some custom animation in my project that I'd rather keep, but when navigating back from another view the animation occurs before my own animations causing a clunky delay. I have a solution for my custom views like this.

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(backTapped))
@objc func backTapped() {
        navigationController?.popViewController(animated: false)
}

However, I'm not sure if I can override the back button from SFSafariViewController. Is this possible, or do I need to move onto custom webviews and handle the code there?

zeytin
  • 5,545
  • 4
  • 14
  • 38
Thomas Kellough
  • 143
  • 1
  • 2
  • 11

1 Answers1

1

Putting some control as usual can solve your problem, please try.

@objc func backTapped() {
        if(webview.canGoBack) {
             webview.goBack()
        } else {
             self.navigationController.popViewController(animated:false)
        }
}
zeytin
  • 5,545
  • 4
  • 14
  • 38
  • The issue is it's an SFSafariViewController(). I don't have code access to the inside of that view controller so I can't add functions to it. Or if I can I'm not sure how I can do that. – Thomas Kellough Oct 28 '20 at 18:26
  • it is supposed to be a webView and you can access it right ? – zeytin Oct 28 '20 at 19:34
  • 1
    Kind of. You can use it in lieu of a webview. https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller But I can't access the class like I can if I made a custom webview. – Thomas Kellough Oct 28 '20 at 19:35